Ampel
Dependencies: mbed
Fork of 2016-01-25_LABOR_Ampel by
Ampel.cpp@0:b13d29153354, 2016-01-25 (annotated)
- Committer:
- tauchi88
- Date:
- Mon Jan 25 18:49:32 2016 +0000
- Revision:
- 0:b13d29153354
ampel
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tauchi88 | 0:b13d29153354 | 1 | #include "mbed.h" |
tauchi88 | 0:b13d29153354 | 2 | #include "BtnEventM0.h" |
tauchi88 | 0:b13d29153354 | 3 | |
tauchi88 | 0:b13d29153354 | 4 | //Ledbar |
tauchi88 | 0:b13d29153354 | 5 | BusOut lb1(P1_7, P1_6, P1_4, P1_3, P1_1, P1_0, LED4, LED3, LED2, LED1); |
tauchi88 | 0:b13d29153354 | 6 | |
tauchi88 | 0:b13d29153354 | 7 | // Statusled zeigt uns in welchem Zustand ide Statmachine gerade ist |
tauchi88 | 0:b13d29153354 | 8 | BusOut stLED(P1_13, P1_12); |
tauchi88 | 0:b13d29153354 | 9 | |
tauchi88 | 0:b13d29153354 | 10 | //erledigt für uns die Abfrage der positiven Flange |
tauchi88 | 0:b13d29153354 | 11 | BtnEventM0 sw4(P1_16), sw3(P0_23); //sw4 vorwärts sw3 rückwärts |
tauchi88 | 0:b13d29153354 | 12 | |
tauchi88 | 0:b13d29153354 | 13 | Serial pc(USBTX, USBRX); |
tauchi88 | 0:b13d29153354 | 14 | |
tauchi88 | 0:b13d29153354 | 15 | const int St_Rot = 1; |
tauchi88 | 0:b13d29153354 | 16 | const int St_Gelb = 1; |
tauchi88 | 0:b13d29153354 | 17 | const int St_Gruen = 1; |
tauchi88 | 0:b13d29153354 | 18 | |
tauchi88 | 0:b13d29153354 | 19 | |
tauchi88 | 0:b13d29153354 | 20 | class Ampel |
tauchi88 | 0:b13d29153354 | 21 | { |
tauchi88 | 0:b13d29153354 | 22 | public: |
tauchi88 | 0:b13d29153354 | 23 | void Init() { |
tauchi88 | 0:b13d29153354 | 24 | state=St_Rot; |
tauchi88 | 0:b13d29153354 | 25 | t1.start(); |
tauchi88 | 0:b13d29153354 | 26 | t2.start(); |
tauchi88 | 0:b13d29153354 | 27 | t3.start(); |
tauchi88 | 0:b13d29153354 | 28 | } |
tauchi88 | 0:b13d29153354 | 29 | void Rot(); |
tauchi88 | 0:b13d29153354 | 30 | void Gelb(); |
tauchi88 | 0:b13d29153354 | 31 | void Gruen(); |
tauchi88 | 0:b13d29153354 | 32 | public: |
tauchi88 | 0:b13d29153354 | 33 | void RotAction(); |
tauchi88 | 0:b13d29153354 | 34 | void GelbAction(); |
tauchi88 | 0:b13d29153354 | 35 | void GruenAction(); |
tauchi88 | 0:b13d29153354 | 36 | public: |
tauchi88 | 0:b13d29153354 | 37 | int state; |
tauchi88 | 0:b13d29153354 | 38 | Timer t1; //blinken |
tauchi88 | 0:b13d29153354 | 39 | Timer t2; //mit 10 Hz zur anzeige schicken |
tauchi88 | 0:b13d29153354 | 40 | Timer t3; //Zeit bis zum umschalten anzeigen |
tauchi88 | 0:b13d29153354 | 41 | |
tauchi88 | 0:b13d29153354 | 42 | }; |
tauchi88 | 0:b13d29153354 | 43 | |
tauchi88 | 0:b13d29153354 | 44 | Ampel amp; |
tauchi88 | 0:b13d29153354 | 45 | |
tauchi88 | 0:b13d29153354 | 46 | |
tauchi88 | 0:b13d29153354 | 47 | int main(void) |
tauchi88 | 0:b13d29153354 | 48 | { |
tauchi88 | 0:b13d29153354 | 49 | amp.Init(); |
tauchi88 | 0:b13d29153354 | 50 | sw3.Init(); |
tauchi88 | 0:b13d29153354 | 51 | sw4.Init(); |
tauchi88 | 0:b13d29153354 | 52 | pc.baud(125000); |
tauchi88 | 0:b13d29153354 | 53 | |
tauchi88 | 0:b13d29153354 | 54 | |
tauchi88 | 0:b13d29153354 | 55 | while(1) { |
tauchi88 | 0:b13d29153354 | 56 | |
tauchi88 | 0:b13d29153354 | 57 | } |
tauchi88 | 0:b13d29153354 | 58 | } |
tauchi88 | 0:b13d29153354 | 59 | |
tauchi88 | 0:b13d29153354 | 60 | //----------------------------------------------------------------------------------------------------- |
tauchi88 | 0:b13d29153354 | 61 | |
tauchi88 | 0:b13d29153354 | 62 | void Ampel::Rot() |
tauchi88 | 0:b13d29153354 | 63 | { |
tauchi88 | 0:b13d29153354 | 64 | //einmalige aktion |
tauchi88 | 0:b13d29153354 | 65 | pc.printf("ROT\n"); |
tauchi88 | 0:b13d29153354 | 66 | t3.reset(); |
tauchi88 | 0:b13d29153354 | 67 | while(1) { |
tauchi88 | 0:b13d29153354 | 68 | //Btn und Zeit abfragen (möglicher Zustandwechsel) |
tauchi88 | 0:b13d29153354 | 69 | if(t3.read_ms()>3000) { |
tauchi88 | 0:b13d29153354 | 70 | state=St_Gelb; |
tauchi88 | 0:b13d29153354 | 71 | return; |
tauchi88 | 0:b13d29153354 | 72 | } |
tauchi88 | 0:b13d29153354 | 73 | RotAction(); |
tauchi88 | 0:b13d29153354 | 74 | } |
tauchi88 | 0:b13d29153354 | 75 | |
tauchi88 | 0:b13d29153354 | 76 | } |
tauchi88 | 0:b13d29153354 | 77 | |
tauchi88 | 0:b13d29153354 | 78 | void Ampel::RotAction() |
tauchi88 | 0:b13d29153354 | 79 | { |
tauchi88 | 0:b13d29153354 | 80 | //Blinken |
tauchi88 | 0:b13d29153354 | 81 | if(t1.read_ms()>500) { |
tauchi88 | 0:b13d29153354 | 82 | t1.reset(); |
tauchi88 | 0:b13d29153354 | 83 | if(lb1==0) |
tauchi88 | 0:b13d29153354 | 84 | lb1=1; //bei Gelb soll dann lb=4 |
tauchi88 | 0:b13d29153354 | 85 | else |
tauchi88 | 0:b13d29153354 | 86 | lb1 =0; |
tauchi88 | 0:b13d29153354 | 87 | } |
tauchi88 | 0:b13d29153354 | 88 | //RestZeit mit 10 Hz zur Anzeige senden |
tauchi88 | 0:b13d29153354 | 89 | if(t2.read_ms()>100) { |
tauchi88 | 0:b13d29153354 | 90 | t2.reset(); |
tauchi88 | 0:b13d29153354 | 91 | pc.printf("2 %d\n", t3.read_ms()/100); //Zeitanzeige auf 1/10sec genau |
tauchi88 | 0:b13d29153354 | 92 | } |
tauchi88 | 0:b13d29153354 | 93 | } |
tauchi88 | 0:b13d29153354 | 94 |