Bertl Ping Pong Demo Bertl reacts to Buttons. Leds are blinking dependent on current direction

Dependencies:   BertlLib mbed

Committer:
hollegha2
Date:
Fri Apr 25 14:38:09 2014 +0000
Revision:
0:2033217d2140
Child:
1:81bbec75e875
Ping Pong Prog. for Bertl

Who changed what in which revision?

UserRevisionLine numberNew 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 0:2033217d2140 5 #include "BertlObjects.h"
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 0:2033217d2140 18 leds=6; wait(0.8);
hollegha2 0:2033217d2140 19 pex.WaitUntilButtonPressed();
hollegha2 0:2033217d2140 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 0:2033217d2140 40 BlinkTask();
hollegha2 0:2033217d2140 41 wait(0.005);
hollegha2 0:2033217d2140 42 }
hollegha2 0:2033217d2140 43
hollegha2 0:2033217d2140 44 return 1;
hollegha2 0:2033217d2140 45 }
hollegha2 0:2033217d2140 46
hollegha2 0:2033217d2140 47 void BlinkTask()
hollegha2 0:2033217d2140 48 {
hollegha2 0:2033217d2140 49 if( stw.read_ms()<200 )
hollegha2 0:2033217d2140 50 return;
hollegha2 0:2033217d2140 51 stw.reset();
hollegha2 0:2033217d2140 52 if( gBlinkMode==1 )
hollegha2 0:2033217d2140 53 pex.ToggleLeds(LED_FL1);
hollegha2 0:2033217d2140 54 if( gBlinkMode==2 )
hollegha2 0:2033217d2140 55 pex.ToggleLeds(LED_FR1);
hollegha2 0:2033217d2140 56 if( gBlinkMode==3 )
hollegha2 0:2033217d2140 57 pex.ToggleLeds(LED_ALL_FRONT);
hollegha2 0:2033217d2140 58 if( gBlinkMode==4 )
hollegha2 0:2033217d2140 59 pex.ToggleLeds(LED_ALL_BACK);
hollegha2 0:2033217d2140 60 }
hollegha2 0:2033217d2140 61