Martin Werluschnig
/
BertlPingPongBlink
BertlPingPong
BertlPingPongBlink.cpp@0:61b574a87750, 2018-11-15 (annotated)
- Committer:
- martwerl
- Date:
- Thu Nov 15 17:46:11 2018 +0000
- Revision:
- 0:61b574a87750
BertlPingPong
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
martwerl | 0:61b574a87750 | 1 | #include "mbed.h" |
martwerl | 0:61b574a87750 | 2 | #include "Serial_HL.h" |
martwerl | 0:61b574a87750 | 3 | #include "Bertl14.h" |
martwerl | 0:61b574a87750 | 4 | #include "BertlObjects.h" |
martwerl | 0:61b574a87750 | 5 | |
martwerl | 0:61b574a87750 | 6 | // main=2^0 LS ENC 2^2 |
martwerl | 0:61b574a87750 | 7 | BusOut boardPow(p30, P1_6, P1_7); |
martwerl | 0:61b574a87750 | 8 | |
martwerl | 0:61b574a87750 | 9 | // ls5 nur beim Betrl15 |
martwerl | 0:61b574a87750 | 10 | // AnalogInHL ls1(p18), ls2(p16), ls3(p19), ls4(p17); // B14 |
martwerl | 0:61b574a87750 | 11 | |
martwerl | 0:61b574a87750 | 12 | //AnalogInHL ls1(p18), ls2(p16), ls3(p20), ls4(p19), ls5(p17); // B15 |
martwerl | 0:61b574a87750 | 13 | //void ButonBlinker(); |
martwerl | 0:61b574a87750 | 14 | |
martwerl | 0:61b574a87750 | 15 | //void MotorTest (); |
martwerl | 0:61b574a87750 | 16 | |
martwerl | 0:61b574a87750 | 17 | void BackW(); |
martwerl | 0:61b574a87750 | 18 | void ForW(); |
martwerl | 0:61b574a87750 | 19 | void BlinkTask(); |
martwerl | 0:61b574a87750 | 20 | int direction = 0; //0= zurück, 1 = vorwärts |
martwerl | 0:61b574a87750 | 21 | Timer t1; |
martwerl | 0:61b574a87750 | 22 | |
martwerl | 0:61b574a87750 | 23 | |
martwerl | 0:61b574a87750 | 24 | |
martwerl | 0:61b574a87750 | 25 | |
martwerl | 0:61b574a87750 | 26 | |
martwerl | 0:61b574a87750 | 27 | int main(void) |
martwerl | 0:61b574a87750 | 28 | { |
martwerl | 0:61b574a87750 | 29 | boardPow = 1; wait_ms(10); |
martwerl | 0:61b574a87750 | 30 | InitBertl(); |
martwerl | 0:61b574a87750 | 31 | pex.useISR = 0; leds = 9; |
martwerl | 0:61b574a87750 | 32 | pex.ClearLeds(); |
martwerl | 0:61b574a87750 | 33 | t1.start(); |
martwerl | 0:61b574a87750 | 34 | pex.WaitUntilButtonPressed(); |
martwerl | 0:61b574a87750 | 35 | while (1) |
martwerl | 0:61b574a87750 | 36 | { |
martwerl | 0:61b574a87750 | 37 | //ButonBlinker(); |
martwerl | 0:61b574a87750 | 38 | //MotorTest (); |
martwerl | 0:61b574a87750 | 39 | BackW(); |
martwerl | 0:61b574a87750 | 40 | wait_ms(1000); |
martwerl | 0:61b574a87750 | 41 | ForW(); |
martwerl | 0:61b574a87750 | 42 | wait_ms(1000); |
martwerl | 0:61b574a87750 | 43 | } |
martwerl | 0:61b574a87750 | 44 | |
martwerl | 0:61b574a87750 | 45 | return 1; |
martwerl | 0:61b574a87750 | 46 | } |
martwerl | 0:61b574a87750 | 47 | /* |
martwerl | 0:61b574a87750 | 48 | void ButonBlinker() |
martwerl | 0:61b574a87750 | 49 | { |
martwerl | 0:61b574a87750 | 50 | pex.ReadButtons(); |
martwerl | 0:61b574a87750 | 51 | |
martwerl | 0:61b574a87750 | 52 | if (pex.IsButton(BTN_FLL)) |
martwerl | 0:61b574a87750 | 53 | { |
martwerl | 0:61b574a87750 | 54 | pex.SetLeds(LED_FL1|LED_FL2); |
martwerl | 0:61b574a87750 | 55 | } |
martwerl | 0:61b574a87750 | 56 | |
martwerl | 0:61b574a87750 | 57 | if (pex.IsButton(BTN_FRR)) |
martwerl | 0:61b574a87750 | 58 | { |
martwerl | 0:61b574a87750 | 59 | pex.SetLeds(LED_FR1|LED_FR2); |
martwerl | 0:61b574a87750 | 60 | } |
martwerl | 0:61b574a87750 | 61 | wait_ms(100); |
martwerl | 0:61b574a87750 | 62 | pex.ClearLeds(); |
martwerl | 0:61b574a87750 | 63 | wait_ms(100); |
martwerl | 0:61b574a87750 | 64 | } |
martwerl | 0:61b574a87750 | 65 | */ |
martwerl | 0:61b574a87750 | 66 | |
martwerl | 0:61b574a87750 | 67 | /* |
martwerl | 0:61b574a87750 | 68 | void MotorTest () |
martwerl | 0:61b574a87750 | 69 | { |
martwerl | 0:61b574a87750 | 70 | if (pex.IsButton(BTN_FRR||BTN_FLL)) |
martwerl | 0:61b574a87750 | 71 | { |
martwerl | 0:61b574a87750 | 72 | mL.SetPow(-0.2); |
martwerl | 0:61b574a87750 | 73 | mR.SetPow(-0.2); |
martwerl | 0:61b574a87750 | 74 | } |
martwerl | 0:61b574a87750 | 75 | |
martwerl | 0:61b574a87750 | 76 | |
martwerl | 0:61b574a87750 | 77 | else if (pex.IsButton(BTN_BR||BTN_BL)) |
martwerl | 0:61b574a87750 | 78 | { |
martwerl | 0:61b574a87750 | 79 | mL.SetPow(0.2); |
martwerl | 0:61b574a87750 | 80 | mR.SetPow(0.2); |
martwerl | 0:61b574a87750 | 81 | } |
martwerl | 0:61b574a87750 | 82 | |
martwerl | 0:61b574a87750 | 83 | //mL.SetPow(0.2); |
martwerl | 0:61b574a87750 | 84 | //mR.SetPow(0.2); |
martwerl | 0:61b574a87750 | 85 | |
martwerl | 0:61b574a87750 | 86 | //wait_ms(2000); |
martwerl | 0:61b574a87750 | 87 | |
martwerl | 0:61b574a87750 | 88 | //mL.SetPow(-0.2); |
martwerl | 0:61b574a87750 | 89 | //mR.SetPow(-0.2); |
martwerl | 0:61b574a87750 | 90 | |
martwerl | 0:61b574a87750 | 91 | //wait_ms(2000); |
martwerl | 0:61b574a87750 | 92 | |
martwerl | 0:61b574a87750 | 93 | |
martwerl | 0:61b574a87750 | 94 | |
martwerl | 0:61b574a87750 | 95 | |
martwerl | 0:61b574a87750 | 96 | } |
martwerl | 0:61b574a87750 | 97 | */ |
martwerl | 0:61b574a87750 | 98 | |
martwerl | 0:61b574a87750 | 99 | void BackW() |
martwerl | 0:61b574a87750 | 100 | { |
martwerl | 0:61b574a87750 | 101 | pex.ClearLeds(); |
martwerl | 0:61b574a87750 | 102 | mL.SetPow(0.3); |
martwerl | 0:61b574a87750 | 103 | mR.SetPow(0.3); |
martwerl | 0:61b574a87750 | 104 | direction = 0; |
martwerl | 0:61b574a87750 | 105 | |
martwerl | 0:61b574a87750 | 106 | // pex.SetLeds(LED_BL1 | LED_BL2); |
martwerl | 0:61b574a87750 | 107 | // pex.SetLeds(LED_BR1 | LED_BR2); |
martwerl | 0:61b574a87750 | 108 | |
martwerl | 0:61b574a87750 | 109 | while (1) |
martwerl | 0:61b574a87750 | 110 | { |
martwerl | 0:61b574a87750 | 111 | pex.ReadButtons(); |
martwerl | 0:61b574a87750 | 112 | BlinkTask(); |
martwerl | 0:61b574a87750 | 113 | |
martwerl | 0:61b574a87750 | 114 | if (pex.IsAnyBackButton()) |
martwerl | 0:61b574a87750 | 115 | { |
martwerl | 0:61b574a87750 | 116 | break; |
martwerl | 0:61b574a87750 | 117 | } |
martwerl | 0:61b574a87750 | 118 | |
martwerl | 0:61b574a87750 | 119 | } |
martwerl | 0:61b574a87750 | 120 | mL.SetPow(0); |
martwerl | 0:61b574a87750 | 121 | mR.SetPow(0); |
martwerl | 0:61b574a87750 | 122 | |
martwerl | 0:61b574a87750 | 123 | |
martwerl | 0:61b574a87750 | 124 | } |
martwerl | 0:61b574a87750 | 125 | |
martwerl | 0:61b574a87750 | 126 | |
martwerl | 0:61b574a87750 | 127 | void ForW() |
martwerl | 0:61b574a87750 | 128 | { |
martwerl | 0:61b574a87750 | 129 | pex.ClearLeds(); |
martwerl | 0:61b574a87750 | 130 | mL.SetPow(-0.3); |
martwerl | 0:61b574a87750 | 131 | mR.SetPow(-0.3); |
martwerl | 0:61b574a87750 | 132 | direction = 1; |
martwerl | 0:61b574a87750 | 133 | |
martwerl | 0:61b574a87750 | 134 | // pex.SetLeds(LED_FL1 | LED_FL2); |
martwerl | 0:61b574a87750 | 135 | // pex.SetLeds(LED_FR1 | LED_FR2); |
martwerl | 0:61b574a87750 | 136 | |
martwerl | 0:61b574a87750 | 137 | while (1) |
martwerl | 0:61b574a87750 | 138 | { |
martwerl | 0:61b574a87750 | 139 | pex.ReadButtons(); |
martwerl | 0:61b574a87750 | 140 | BlinkTask(); |
martwerl | 0:61b574a87750 | 141 | |
martwerl | 0:61b574a87750 | 142 | if (pex.IsAnyFrontButton()) |
martwerl | 0:61b574a87750 | 143 | { |
martwerl | 0:61b574a87750 | 144 | break; |
martwerl | 0:61b574a87750 | 145 | } |
martwerl | 0:61b574a87750 | 146 | |
martwerl | 0:61b574a87750 | 147 | } |
martwerl | 0:61b574a87750 | 148 | mL.SetPow(0); |
martwerl | 0:61b574a87750 | 149 | mR.SetPow(0); |
martwerl | 0:61b574a87750 | 150 | |
martwerl | 0:61b574a87750 | 151 | } |
martwerl | 0:61b574a87750 | 152 | |
martwerl | 0:61b574a87750 | 153 | void BlinkTask() |
martwerl | 0:61b574a87750 | 154 | { //TIMER |
martwerl | 0:61b574a87750 | 155 | if (t1.read_ms()>100) // alle 100ms = 10Hz |
martwerl | 0:61b574a87750 | 156 | { |
martwerl | 0:61b574a87750 | 157 | t1.reset(); // timer neu starten |
martwerl | 0:61b574a87750 | 158 | if (direction == 0) |
martwerl | 0:61b574a87750 | 159 | { |
martwerl | 0:61b574a87750 | 160 | pex.ToggleLeds(LED_BL1 | LED_BL2); |
martwerl | 0:61b574a87750 | 161 | pex.ToggleLeds(LED_BR1 | LED_BR2); |
martwerl | 0:61b574a87750 | 162 | } |
martwerl | 0:61b574a87750 | 163 | else |
martwerl | 0:61b574a87750 | 164 | { |
martwerl | 0:61b574a87750 | 165 | pex.ToggleLeds(LED_FL1 | LED_FL2); |
martwerl | 0:61b574a87750 | 166 | pex.ToggleLeds(LED_FR1 | LED_FR2); |
martwerl | 0:61b574a87750 | 167 | } |
martwerl | 0:61b574a87750 | 168 | } |
martwerl | 0:61b574a87750 | 169 | } |