Code to control a Traxster robot using a Wimote and Android app
Fork of BlueUSB by
main.cpp@1:accdaa84fe8d, 2014-04-28 (annotated)
- Committer:
- aswild
- Date:
- Mon Apr 28 16:06:32 2014 +0000
- Revision:
- 1:accdaa84fe8d
- Parent:
- 0:606b230e5b4a
Wiimote controlled Traxster robot using BlueUSB
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
peterbarrett1967 | 0:606b230e5b4a | 1 | #include "mbed.h" |
peterbarrett1967 | 0:606b230e5b4a | 2 | #include "USBHost.h" |
peterbarrett1967 | 0:606b230e5b4a | 3 | #include "Utils.h" |
peterbarrett1967 | 0:606b230e5b4a | 4 | |
aswild | 1:accdaa84fe8d | 5 | Serial pc(USBTX, USBRX); |
aswild | 1:accdaa84fe8d | 6 | Serial rob(p13, p14); |
aswild | 1:accdaa84fe8d | 7 | DigitalIn modeSw(p19); |
peterbarrett1967 | 0:606b230e5b4a | 8 | |
aswild | 1:accdaa84fe8d | 9 | // because of wiring on the breadboard, these pins are connected to 5V or |
aswild | 1:accdaa84fe8d | 10 | // ground (for the robot and BlueSMiRF connections) so configure them as inputs |
aswild | 1:accdaa84fe8d | 11 | // to avoid shorting anything out |
aswild | 1:accdaa84fe8d | 12 | DigitalIn di11(p11); |
aswild | 1:accdaa84fe8d | 13 | DigitalIn di12(p12); |
aswild | 1:accdaa84fe8d | 14 | DigitalIn di15(p15); |
aswild | 1:accdaa84fe8d | 15 | DigitalIn di16(p16); |
aswild | 1:accdaa84fe8d | 16 | |
aswild | 1:accdaa84fe8d | 17 | extern DigitalOut led1, led2, led3, led4; |
aswild | 1:accdaa84fe8d | 18 | |
aswild | 1:accdaa84fe8d | 19 | Ticker failsafeTick; |
aswild | 1:accdaa84fe8d | 20 | time_t lastReportTime; |
aswild | 1:accdaa84fe8d | 21 | |
aswild | 1:accdaa84fe8d | 22 | void failsafe() |
peterbarrett1967 | 0:606b230e5b4a | 23 | { |
aswild | 1:accdaa84fe8d | 24 | time_t t = time(NULL); |
aswild | 1:accdaa84fe8d | 25 | if (t > lastReportTime+1) |
peterbarrett1967 | 0:606b230e5b4a | 26 | { |
aswild | 1:accdaa84fe8d | 27 | rob.puts("stop\r"); |
aswild | 1:accdaa84fe8d | 28 | led3 = 1; |
peterbarrett1967 | 0:606b230e5b4a | 29 | } |
peterbarrett1967 | 0:606b230e5b4a | 30 | } |
peterbarrett1967 | 0:606b230e5b4a | 31 | |
aswild | 1:accdaa84fe8d | 32 | void RunWiimote(); |
aswild | 1:accdaa84fe8d | 33 | void RunAndroid(); |
peterbarrett1967 | 0:606b230e5b4a | 34 | |
peterbarrett1967 | 0:606b230e5b4a | 35 | int main() |
peterbarrett1967 | 0:606b230e5b4a | 36 | { |
aswild | 1:accdaa84fe8d | 37 | modeSw.mode(PullDown); |
aswild | 1:accdaa84fe8d | 38 | rob.baud(19200); |
aswild | 1:accdaa84fe8d | 39 | set_time(9001); |
aswild | 1:accdaa84fe8d | 40 | failsafeTick.attach(&failsafe, 0.1); |
aswild | 1:accdaa84fe8d | 41 | |
aswild | 1:accdaa84fe8d | 42 | printf("Vroom Vroom!\n"); |
aswild | 1:accdaa84fe8d | 43 | if (modeSw) |
aswild | 1:accdaa84fe8d | 44 | RunWiimote(); |
aswild | 1:accdaa84fe8d | 45 | else |
aswild | 1:accdaa84fe8d | 46 | RunAndroid(); |
peterbarrett1967 | 0:606b230e5b4a | 47 | } |