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
main.cpp@0:b5f79b4f741d, 2016-03-15 (annotated)
- Committer:
- beaglescout007
- Date:
- Tue Mar 15 11:39:04 2016 +0000
- Revision:
- 0:b5f79b4f741d
Release
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
beaglescout007 | 0:b5f79b4f741d | 1 | #include "mbed.h" |
beaglescout007 | 0:b5f79b4f741d | 2 | #include "USBHostGamepad.h" |
beaglescout007 | 0:b5f79b4f741d | 3 | |
beaglescout007 | 0:b5f79b4f741d | 4 | USBHostGamepad *pad; |
beaglescout007 | 0:b5f79b4f741d | 5 | |
beaglescout007 | 0:b5f79b4f741d | 6 | // LED |
beaglescout007 | 0:b5f79b4f741d | 7 | DigitalOut red(PB_5); |
beaglescout007 | 0:b5f79b4f741d | 8 | DigitalOut yellow(PA_10); |
beaglescout007 | 0:b5f79b4f741d | 9 | |
beaglescout007 | 0:b5f79b4f741d | 10 | int main() |
beaglescout007 | 0:b5f79b4f741d | 11 | { |
beaglescout007 | 0:b5f79b4f741d | 12 | // USB Gmaepad Initialize |
beaglescout007 | 0:b5f79b4f741d | 13 | pad = new USBHostGamepad(); |
beaglescout007 | 0:b5f79b4f741d | 14 | if (!pad->connect()) { |
beaglescout007 | 0:b5f79b4f741d | 15 | printf("USB Gamepad not found.\r\n"); |
beaglescout007 | 0:b5f79b4f741d | 16 | while(1); |
beaglescout007 | 0:b5f79b4f741d | 17 | } |
beaglescout007 | 0:b5f79b4f741d | 18 | |
beaglescout007 | 0:b5f79b4f741d | 19 | while(1) |
beaglescout007 | 0:b5f79b4f741d | 20 | { |
beaglescout007 | 0:b5f79b4f741d | 21 | USBHost::poll(); |
beaglescout007 | 0:b5f79b4f741d | 22 | |
beaglescout007 | 0:b5f79b4f741d | 23 | red = pad->report[4] & 0x20; |
beaglescout007 | 0:b5f79b4f741d | 24 | yellow = pad->report[4] & 0x40; |
beaglescout007 | 0:b5f79b4f741d | 25 | |
beaglescout007 | 0:b5f79b4f741d | 26 | 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]); |
beaglescout007 | 0:b5f79b4f741d | 27 | wait_ms(16); |
beaglescout007 | 0:b5f79b4f741d | 28 | } |
beaglescout007 | 0:b5f79b4f741d | 29 | } |