Reading data from a USB Gamepad with USB-Host mode.

Dependencies:   mbed

Fork of Nucleo_Ex04_USBPAD by woodstock .

main.cpp

Committer:
beaglescout007
Date:
2016-03-15
Revision:
0:b5f79b4f741d
Child:
1:94e011434208

File content as of revision 0:b5f79b4f741d:

#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);
    }
}