This example demonstrates the reading of the USB Gamepad in the Nucleo.
Intro
This example demonstrates the reading of the USB Gamepad in the Nucleo.
Parts
STM32 Nucleo F446RE |
USB Connector |
LED 2pcs |
Register 470 ohm 2pcs |
Breadboard |
Wires |
Wiring diagram
This circuit diagram was created by fritzing.
USB con. | Nucleo |
---|---|
GND | GND |
+ | PA_12 |
- | PA_11 |
5V | 5V |
Original Library
- F401RE-USBHost by Norimasa Okamoto
- USBHostGamepad by Yuuichi Akagawa
Diff: main.cpp
- Revision:
- 0:b5f79b4f741d
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Mar 15 11:39:04 2016 +0000 @@ -0,0 +1,29 @@ +#include "mbed.h" +#include "USBHostGamepad.h" + +USBHostGamepad *pad; + +// LED +DigitalOut red(PB_5); +DigitalOut yellow(PA_10); + +int main() +{ + // USB Gmaepad Initialize + pad = new USBHostGamepad(); + if (!pad->connect()) { + printf("USB Gamepad not found.\r\n"); + while(1); + } + + while(1) + { + USBHost::poll(); + + red = pad->report[4] & 0x20; + yellow = pad->report[4] & 0x40; + + printf("%02x %02x %02x %02x %02x %02x %02x %02x\r\n", pad->report[0],pad->report[1],pad->report[2],pad->report[3],pad->report[4],pad->report[5],pad->report[6],pad->report[7]); + wait_ms(16); + } +}