A program to show the use of a wireless xbox 360 controller. Has details on what data is given out from the controller as well as normalized values for the triggers and sticks
Dependencies: USBHost USBHostXpad mbed
Fork of USBHostXpad_HelloWorld by
main.cpp
- Committer:
- okini3939
- Date:
- 2013-12-10
- Revision:
- 9:16ce7a241108
- Parent:
- 4:f8a5c8aa895a
- Child:
- 10:4b0c8727f0c3
File content as of revision 9:16ce7a241108:
#include "mbed.h" #include "USBHostXpad.h" Serial pc(USBTX, USBRX); DigitalOut led(LED1); void onXpadEvent (int buttons, int stick_lx, int stick_ly, int stick_rx, int stick_ry, int trigger_l, int trigger_r) { std::printf("Xpad: %04x %-5d %-5d %-5d %-5d %02x %02x\r\n", buttons, stick_lx, stick_ly, stick_rx, stick_ry, trigger_l, trigger_r); } void xpad_task(void const *) { USBHostXpad xpad; while(1) { // try to connect a Xbox 360 Wireless Controller while(!xpad.connect()) Thread::wait(500); // when connected, attach handler called on xpad event xpad.attachEvent(onXpadEvent); // wait until the mouse is disconnected while(xpad.connected()) Thread::wait(500); } } int main() { pc.baud(115200); pc.printf("----------\r\n"); Thread xpadTask(xpad_task, NULL, osPriorityNormal, 1024 * 4); while(1) { led=!led; Thread::wait(500); } }