bertl

Dependencies:   BertlLib mbed

Fork of BertlTemplate2 by michael hollegha

Committer:
tauchi88
Date:
Mon May 02 17:10:27 2016 +0000
Revision:
4:260550801324
f?r vici

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tauchi88 4:260550801324 1
tauchi88 4:260550801324 2 #include "mbed.h"
tauchi88 4:260550801324 3 #include "Serial_HL.h"
tauchi88 4:260550801324 4 #include "Bertl14.h"
tauchi88 4:260550801324 5 #include "BertlObjects.h"
tauchi88 4:260550801324 6
tauchi88 4:260550801324 7 // main=2^0 LS ENC 2^2
tauchi88 4:260550801324 8 BusOut boardPow(p30, P1_6, P1_7);
tauchi88 4:260550801324 9 Timer t2, t3;
tauchi88 4:260550801324 10 //---------------------------------------------------------------
tauchi88 4:260550801324 11
tauchi88 4:260550801324 12
tauchi88 4:260550801324 13
tauchi88 4:260550801324 14 void LeftCurve()
tauchi88 4:260550801324 15 {
tauchi88 4:260550801324 16 t3.reset();
tauchi88 4:260550801324 17 mL.SetPow2(0.2);
tauchi88 4:260550801324 18 mR.SetPow2(0.4);
tauchi88 4:260550801324 19 while (1) {
tauchi88 4:260550801324 20 if(t3.read_ms()>5000)
tauchi88 4:260550801324 21 break;
tauchi88 4:260550801324 22 if(t2.read_ms()>100)
tauchi88 4:260550801324 23 {
tauchi88 4:260550801324 24 t2.reset();
tauchi88 4:260550801324 25 pex.ToggleLeds(LED_FL1);
tauchi88 4:260550801324 26 }
tauchi88 4:260550801324 27 }
tauchi88 4:260550801324 28 mL.SetPow2(0.0);
tauchi88 4:260550801324 29 mR.SetPow2(0.0);
tauchi88 4:260550801324 30 pex.ClearLeds();
tauchi88 4:260550801324 31 }
tauchi88 4:260550801324 32
tauchi88 4:260550801324 33 //---------------------------------------------------------------
tauchi88 4:260550801324 34
tauchi88 4:260550801324 35 void RightCurve()
tauchi88 4:260550801324 36 {
tauchi88 4:260550801324 37 t3.reset();
tauchi88 4:260550801324 38 mL.SetPow2(0.4);
tauchi88 4:260550801324 39 mR.SetPow2(0.2);
tauchi88 4:260550801324 40 while (1) {
tauchi88 4:260550801324 41 if(t3.read_ms()>5000)
tauchi88 4:260550801324 42 break;
tauchi88 4:260550801324 43 if(t2.read_ms()>100)
tauchi88 4:260550801324 44 {
tauchi88 4:260550801324 45 t2.reset();
tauchi88 4:260550801324 46 pex.ToggleLeds(LED_FR1);
tauchi88 4:260550801324 47 }
tauchi88 4:260550801324 48 }
tauchi88 4:260550801324 49 mL.SetPow2(0.0);
tauchi88 4:260550801324 50 mR.SetPow2(0.0);
tauchi88 4:260550801324 51 pex.ClearLeds();
tauchi88 4:260550801324 52 }
tauchi88 4:260550801324 53
tauchi88 4:260550801324 54
tauchi88 4:260550801324 55 //---------------------------------------------------------------
tauchi88 4:260550801324 56 void Forward()
tauchi88 4:260550801324 57 {
tauchi88 4:260550801324 58 t3.reset();
tauchi88 4:260550801324 59 mL.SetPow2(0.2);
tauchi88 4:260550801324 60 mR.SetPow2(0.2);
tauchi88 4:260550801324 61 while (1) {
tauchi88 4:260550801324 62 if(t3.read_ms()>5000)
tauchi88 4:260550801324 63 break;
tauchi88 4:260550801324 64 if(t2.read_ms()>100)
tauchi88 4:260550801324 65 {
tauchi88 4:260550801324 66 t2.reset();
tauchi88 4:260550801324 67 pex.ToggleLeds(LED_ALL_FRONT);
tauchi88 4:260550801324 68 }
tauchi88 4:260550801324 69 }
tauchi88 4:260550801324 70 mL.SetPow2(0.0);
tauchi88 4:260550801324 71 mR.SetPow2(0.0);
tauchi88 4:260550801324 72 pex.ClearLeds();
tauchi88 4:260550801324 73 }
tauchi88 4:260550801324 74
tauchi88 4:260550801324 75 //---------------------------------------------------------------
tauchi88 4:260550801324 76 //---------------------------------------------------------------
tauchi88 4:260550801324 77
tauchi88 4:260550801324 78
tauchi88 4:260550801324 79 int main(void)
tauchi88 4:260550801324 80 {
tauchi88 4:260550801324 81 boardPow=1;
tauchi88 4:260550801324 82 wait_ms(10);
tauchi88 4:260550801324 83 InitBertl();
tauchi88 4:260550801324 84 pex.useISR=0;
tauchi88 4:260550801324 85 leds=9;
tauchi88 4:260550801324 86 pex.ClearLeds();
tauchi88 4:260550801324 87
tauchi88 4:260550801324 88
tauchi88 4:260550801324 89 pex.WaitUntilButtonPressed();
tauchi88 4:260550801324 90
tauchi88 4:260550801324 91 t2.start();
tauchi88 4:260550801324 92 t3.start();
tauchi88 4:260550801324 93
tauchi88 4:260550801324 94 while(1) {
tauchi88 4:260550801324 95 pex.ReadButtons();
tauchi88 4:260550801324 96 if( pex.IsButton (BTN_FLL|BTN_FL) )
tauchi88 4:260550801324 97 LeftCurve();
tauchi88 4:260550801324 98 if( pex.IsButton(BTN_FRR|BTN_FR))
tauchi88 4:260550801324 99 RightCurve();
tauchi88 4:260550801324 100 if( pex.IsButton(BTN_FM))
tauchi88 4:260550801324 101 Forward();
tauchi88 4:260550801324 102 }
tauchi88 4:260550801324 103 return 1;
tauchi88 4:260550801324 104 }
tauchi88 4:260550801324 105
tauchi88 4:260550801324 106
tauchi88 4:260550801324 107
tauchi88 4:260550801324 108