Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem trying to control LED using Xbox 360 wireless controller!!!! HELP!!! #149

Closed
Zahroxx opened this issue May 4, 2015 · 6 comments
Closed

Comments

@Zahroxx
Copy link

Zahroxx commented May 4, 2015

I've trying to make an LED to light up if I click button B. But it won't work. The LED kept light up. I don't know whats the problem..

Codes 1
untitled-3

Codes 2
untitled-5

These are samples of my codes. Both didn't work, both gave the same result, kept light up!!
NEED HELP!!!

@Lauszus
Copy link
Collaborator

Lauszus commented May 4, 2015

You can not use pin 50-53, as they are used for SPI communication. Please use a different pin.

@Lauszus Lauszus closed this as completed May 4, 2015
@Zahroxx
Copy link
Author

Zahroxx commented May 4, 2015

but what about the codes? Is it okay or need some improvement?

@Lauszus
Copy link
Collaborator

Lauszus commented May 4, 2015

Why don't you just try it and see if it works?

You can just do it as simple as this:

/*
 Example sketch for the Xbox Wireless Reciver library - developed by Kristian Lauszus
 It supports up to four controllers wirelessly
 For more information see the blog post: http://blog.tkjelectronics.dk/2012/12/xbox-360-receiver-added-to-the-usb-host-library/ or
 send me an e-mail:  kristianl@tkjelectronics.com
 */

#include <XBOXRECV.h>

// Satisfy the IDE, which needs to see the include statment in the ino too.
#ifdef dobogusinclude
#include <spi4teensy3.h>
#include <SPI.h>
#endif

USB Usb;
XBOXRECV Xbox(&Usb);

#define LED LED_BUILTIN

void setup() {
  pinMode(LED, OUTPUT);

  Serial.begin(115200);
#if !defined(__MIPSEL__)
  while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
#endif
  if (Usb.Init() == -1) {
    Serial.print(F("\r\nOSC did not start"));
    while (1); //halt
  }
  Serial.print(F("\r\nXbox Wireless Receiver Library Started"));
}
void loop() {
  Usb.Task();
  if (Xbox.XboxReceiverConnected) {
    for (uint8_t i = 0; i < 4; i++) {
      if (Xbox.Xbox360Connected[i])
        digitalWrite(LED, Xbox.getButtonPress(B, i));
    }
  } else
    digitalWrite(LED, LOW);
}

PS: I saw your comment at my blog: http://blog.tkjelectronics.dk/2012/12/xbox-360-receiver-added-to-the-usb-host-library/comment-page-2/#comment-545324, please don't double post the same question.

@Zahroxx
Copy link
Author

Zahroxx commented May 5, 2015

Yeah, sorry about that. Just want to find the answers quickly.
The code does work, but I need to hold the button to make it light up. I've tried to change from 'getButtonPress' to 'getButtonClick'. It'll also work, but only lights up as I click the button, then lights off.

Still searching for an answers..

@Lauszus
Copy link
Collaborator

Lauszus commented May 5, 2015

Okay. This is not really related to the library though. I recommend asking at something like the Arduino forum for general programming questions.

@Lauszus
Copy link
Collaborator

Lauszus commented May 5, 2015

Anyway here is the code:

bool ledState = false;
void loop() {
  Usb.Task();
  if (Xbox.XboxReceiverConnected) {
    for (uint8_t i = 0; i < 4; i++) {
      if (Xbox.Xbox360Connected[i]) {
        if (Xbox.getButtonClick(B, i))
          ledState = !ledState;
      }
    }
  } else
    ledState = false;
  digitalWrite(LED, ledState);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants