michael hollegha
/
BertlPingPong
Bertl Ping Pong Demo Bertl reacts to Buttons. Leds are blinking dependent on current direction
BertlPingPong.cpp@1:81bbec75e875, 2014-04-25 (annotated)
- Committer:
- hollegha2
- Date:
- Fri Apr 25 19:10:27 2014 +0000
- Revision:
- 1:81bbec75e875
- Parent:
- 0:2033217d2140
- Child:
- 2:fb6f2a6307d3
Rev2
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hollegha2 | 0:2033217d2140 | 1 | |
hollegha2 | 0:2033217d2140 | 2 | #include "mbed.h" |
hollegha2 | 0:2033217d2140 | 3 | #include "Serial_HL.h" |
hollegha2 | 0:2033217d2140 | 4 | #include "Bertl14.h" |
hollegha2 | 1:81bbec75e875 | 5 | #include "BertlObjects.cpp" |
hollegha2 | 0:2033217d2140 | 6 | |
hollegha2 | 0:2033217d2140 | 7 | int gBlinkMode = 1; |
hollegha2 | 0:2033217d2140 | 8 | void BlinkTask(); |
hollegha2 | 0:2033217d2140 | 9 | Timer stw; |
hollegha2 | 0:2033217d2140 | 10 | |
hollegha2 | 0:2033217d2140 | 11 | int main(void) |
hollegha2 | 0:2033217d2140 | 12 | { |
hollegha2 | 0:2033217d2140 | 13 | InitBertl(); |
hollegha2 | 0:2033217d2140 | 14 | pex.useISR=0; leds=9; |
hollegha2 | 0:2033217d2140 | 15 | pex.ClearLeds(); |
hollegha2 | 0:2033217d2140 | 16 | |
hollegha2 | 0:2033217d2140 | 17 | pex.WaitUntilButtonPressed(); |
hollegha2 | 1:81bbec75e875 | 18 | leds=6; wait(0.8); |
hollegha2 | 1:81bbec75e875 | 19 | pex.WaitUntilButtonPressed(); |
hollegha2 | 1:81bbec75e875 | 20 | leds=0; |
hollegha2 | 0:2033217d2140 | 21 | stw.start(); |
hollegha2 | 0:2033217d2140 | 22 | while(1) { |
hollegha2 | 0:2033217d2140 | 23 | pex.ReadButtons(); |
hollegha2 | 0:2033217d2140 | 24 | if( pex.IsButton(BTN_FLL) ) { |
hollegha2 | 0:2033217d2140 | 25 | gBlinkMode=1; pex.ClearLeds(); |
hollegha2 | 0:2033217d2140 | 26 | mL.SetPow(0.2); mR.SetPow(0.9); |
hollegha2 | 0:2033217d2140 | 27 | } |
hollegha2 | 0:2033217d2140 | 28 | else if( pex.IsButton(BTN_FRR) ) { |
hollegha2 | 0:2033217d2140 | 29 | gBlinkMode=2; pex.ClearLeds(); |
hollegha2 | 0:2033217d2140 | 30 | mL.SetPow(0.9); mR.SetPow(0.2); |
hollegha2 | 0:2033217d2140 | 31 | } |
hollegha2 | 0:2033217d2140 | 32 | else if( pex.IsAnyFrontButton() ) { |
hollegha2 | 0:2033217d2140 | 33 | gBlinkMode=4; pex.ClearLeds(); |
hollegha2 | 0:2033217d2140 | 34 | mL.SetPow(-0.9); mR.SetPow(-0.9); |
hollegha2 | 0:2033217d2140 | 35 | } |
hollegha2 | 0:2033217d2140 | 36 | else if( pex.IsAnyBackButton() ) { |
hollegha2 | 0:2033217d2140 | 37 | gBlinkMode=3; pex.ClearLeds(); |
hollegha2 | 0:2033217d2140 | 38 | mL.SetPow(0.9); mR.SetPow(0.9); |
hollegha2 | 0:2033217d2140 | 39 | } |
hollegha2 | 1:81bbec75e875 | 40 | // Blink dependent on value of gBlinkMode |
hollegha2 | 0:2033217d2140 | 41 | BlinkTask(); |
hollegha2 | 1:81bbec75e875 | 42 | wait(0.005); |
hollegha2 | 0:2033217d2140 | 43 | } |
hollegha2 | 0:2033217d2140 | 44 | |
hollegha2 | 0:2033217d2140 | 45 | return 1; |
hollegha2 | 0:2033217d2140 | 46 | } |
hollegha2 | 0:2033217d2140 | 47 | |
hollegha2 | 0:2033217d2140 | 48 | void BlinkTask() |
hollegha2 | 0:2033217d2140 | 49 | { |
hollegha2 | 0:2033217d2140 | 50 | if( stw.read_ms()<200 ) |
hollegha2 | 0:2033217d2140 | 51 | return; |
hollegha2 | 0:2033217d2140 | 52 | stw.reset(); |
hollegha2 | 0:2033217d2140 | 53 | if( gBlinkMode==1 ) |
hollegha2 | 0:2033217d2140 | 54 | pex.ToggleLeds(LED_FL1); |
hollegha2 | 0:2033217d2140 | 55 | if( gBlinkMode==2 ) |
hollegha2 | 0:2033217d2140 | 56 | pex.ToggleLeds(LED_FR1); |
hollegha2 | 0:2033217d2140 | 57 | if( gBlinkMode==3 ) |
hollegha2 | 0:2033217d2140 | 58 | pex.ToggleLeds(LED_ALL_FRONT); |
hollegha2 | 0:2033217d2140 | 59 | if( gBlinkMode==4 ) |
hollegha2 | 0:2033217d2140 | 60 | pex.ToggleLeds(LED_ALL_BACK); |
hollegha2 | 0:2033217d2140 | 61 | } |