Dependencies:   mbed Birdy_BlueWIi

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 
00002 /*
00003     Simple test shell to exercise mouse,keyboard,mass storage and hubs.
00004     Add 2 15k pulldown resistors between D+/D- and ground, attach a usb socket and have at it.
00005 */
00006 
00007 #include "mbed.h"
00008 #include "Wiimote.h"
00009 
00010 //-- Peripheral Declaration --//
00011 DigitalOut led1(LED1);
00012 DigitalOut led2(LED2);
00013 DigitalOut led3(LED3);
00014 DigitalOut led4(LED4);
00015 const int ON = 1;
00016 const int OFF = 0;
00017 
00018 
00019 Serial pc(USBTX, USBRX);
00020 /*
00021 int GetConsoleChar()
00022 {
00023     if (!pc.readable())
00024         return -1;
00025     char c = pc.getc();
00026     pc.putc(c); // echo
00027     return c;
00028 }
00029 */
00030 Wiimote wii;
00031 // this is called by the USB infrastructure when a wii message comes in
00032 void wii_interrupt() {
00033 
00034     // temporary action triggers
00035     if (wii.up)   {
00036         led2 = ON;
00037     } else {
00038         led2 = OFF;
00039     }
00040     if (wii.down) {
00041         led3 = ON;
00042     } else {
00043         led3 = OFF;
00044     }
00045     if (wii.left) {
00046         led1 = ON; 
00047     } else {
00048         led1 = OFF;
00049     }  
00050     if (wii.right) {
00051         led4 = ON;
00052         if (!wii.isOn(WIILED4)) wii.turnOn(WIILED4);
00053     } else {
00054         if (wii.isOn(WIILED4)) wii.turnOff(WIILED4);
00055         led4 = OFF;
00056     }
00057     if (wii.a) {
00058         led1 = led2 = led3 = led4 = ON; 
00059         if (!wii.isOn(WIILED2+WIILED3+WIILED4)) wii.turnOn(WIILED2+WIILED3+WIILED4);
00060     } else {
00061         led1 = led2 = led3 = led4 = OFF;
00062         if (wii.isOn(WIILED2+WIILED3+WIILED4)) wii.turnOff(WIILED2+WIILED3+WIILED4);
00063     }  
00064     if (wii.plus) {
00065         if (!wii.isOn(WIIRUMBLE))wii.turnOn(WIIRUMBLE);
00066     } 
00067     if (wii.minus) {
00068         if (wii.isOn(WIIRUMBLE))wii.turnOff(WIIRUMBLE);
00069     } 
00070 }
00071 
00072 void startWiiCom(const char * wiiMAC);
00073 
00074 int main()
00075 {
00076     char controller01[] = "00:1F:C5:4C:29:99";   // S.NAKAMURA 01
00077     char controller02[] = "00:21:47:F6:21:D8";    // S.NAKAMURA 02
00078     pc.baud(115200);
00079     printf("BlueUSB\nNow get a bunch of usb or bluetooth things and plug them in\n");
00080     startWiiCom(controller01);
00081 }