Markus Höbel
/
TINF_Test_STM_Hoebel
Projekt TINF 7ABELI
mAIn_1.cpp@1:125e4981a54c, 2018-11-29 (annotated)
- Committer:
- markus286
- Date:
- Thu Nov 29 18:40:07 2018 +0000
- Revision:
- 1:125e4981a54c
- Parent:
- 0:603870fc1af3
- Child:
- 2:8abff6365ac4
Fertig
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
markus286 | 0:603870fc1af3 | 1 | #include "mbed.h" |
markus286 | 0:603870fc1af3 | 2 | #include "C12832.h" |
markus286 | 0:603870fc1af3 | 3 | |
markus286 | 1:125e4981a54c | 4 | InterruptIn btn(p14); |
markus286 | 1:125e4981a54c | 5 | |
markus286 | 1:125e4981a54c | 6 | Timer T1; |
markus286 | 0:603870fc1af3 | 7 | |
markus286 | 1:125e4981a54c | 8 | BusOut Leds (LED1, LED2, LED3, LED4); |
markus286 | 0:603870fc1af3 | 9 | |
markus286 | 1:125e4981a54c | 10 | C12832 lcd(p5, p7, p6, p8, p11); |
markus286 | 0:603870fc1af3 | 11 | |
markus286 | 1:125e4981a54c | 12 | enum State {ST_EIN=0, ST_AUS, ST_ENDE}; |
markus286 | 0:603870fc1af3 | 13 | State state; |
markus286 | 0:603870fc1af3 | 14 | |
markus286 | 1:125e4981a54c | 15 | int LedWert = 3, btnCount = 0; |
markus286 | 0:603870fc1af3 | 16 | |
markus286 | 1:125e4981a54c | 17 | bool pressed = false; |
markus286 | 0:603870fc1af3 | 18 | |
markus286 | 1:125e4981a54c | 19 | void rise(void) |
markus286 | 1:125e4981a54c | 20 | { |
markus286 | 1:125e4981a54c | 21 | wait_ms(50); |
markus286 | 1:125e4981a54c | 22 | pressed = true; |
markus286 | 0:603870fc1af3 | 23 | } |
markus286 | 0:603870fc1af3 | 24 | |
markus286 | 1:125e4981a54c | 25 | bool CheckFlag() |
markus286 | 0:603870fc1af3 | 26 | { |
markus286 | 1:125e4981a54c | 27 | if (pressed) { |
markus286 | 1:125e4981a54c | 28 | pressed=false; |
markus286 | 0:603870fc1af3 | 29 | return true; |
markus286 | 0:603870fc1af3 | 30 | } |
markus286 | 0:603870fc1af3 | 31 | return false; |
markus286 | 0:603870fc1af3 | 32 | } |
markus286 | 0:603870fc1af3 | 33 | |
markus286 | 1:125e4981a54c | 34 | void ST_Ein (void) |
markus286 | 0:603870fc1af3 | 35 | { |
markus286 | 1:125e4981a54c | 36 | //Status auf LCD und Serielle |
markus286 | 1:125e4981a54c | 37 | lcd.cls(); // löscht LCD (clear screen) |
markus286 | 0:603870fc1af3 | 38 | lcd.locate(0,0); // x-position, y-position (x: 0-128; y: 0-32) |
markus286 | 1:125e4981a54c | 39 | lcd.printf("State: 1 (EIN)"); |
markus286 | 1:125e4981a54c | 40 | printf("State: 1 (EIN)"); |
markus286 | 0:603870fc1af3 | 41 | // entry |
markus286 | 0:603870fc1af3 | 42 | |
markus286 | 0:603870fc1af3 | 43 | // do |
markus286 | 0:603870fc1af3 | 44 | while(true) { |
markus286 | 1:125e4981a54c | 45 | Leds = LedWert; |
markus286 | 1:125e4981a54c | 46 | |
markus286 | 1:125e4981a54c | 47 | if(CheckFlag()) { |
markus286 | 1:125e4981a54c | 48 | btnCount++; |
markus286 | 1:125e4981a54c | 49 | if(btnCount >= 3){ |
markus286 | 1:125e4981a54c | 50 | btnCount = 0; |
markus286 | 1:125e4981a54c | 51 | LedWert++; |
markus286 | 1:125e4981a54c | 52 | state = ST_AUS; |
markus286 | 1:125e4981a54c | 53 | |
markus286 | 1:125e4981a54c | 54 | // exit |
markus286 | 1:125e4981a54c | 55 | return; |
markus286 | 1:125e4981a54c | 56 | } |
markus286 | 1:125e4981a54c | 57 | } |
markus286 | 1:125e4981a54c | 58 | } |
markus286 | 1:125e4981a54c | 59 | } |
markus286 | 1:125e4981a54c | 60 | |
markus286 | 1:125e4981a54c | 61 | void ST_Aus (void) |
markus286 | 1:125e4981a54c | 62 | { |
markus286 | 1:125e4981a54c | 63 | //Status auf LCD und Serielle |
markus286 | 1:125e4981a54c | 64 | lcd.cls(); // löscht LCD (clear screen) |
markus286 | 1:125e4981a54c | 65 | lcd.locate(0,0); // x-position, y-position (x: 0-128; y: 0-32) |
markus286 | 1:125e4981a54c | 66 | lcd.printf("State: 2 (AUS)"); |
markus286 | 1:125e4981a54c | 67 | printf("State: 2 (AUS)"); |
markus286 | 0:603870fc1af3 | 68 | |
markus286 | 1:125e4981a54c | 69 | // entry |
markus286 | 1:125e4981a54c | 70 | |
markus286 | 1:125e4981a54c | 71 | // do |
markus286 | 1:125e4981a54c | 72 | while(true) { |
markus286 | 1:125e4981a54c | 73 | Leds = 0; |
markus286 | 1:125e4981a54c | 74 | |
markus286 | 1:125e4981a54c | 75 | if(CheckFlag()) { |
markus286 | 1:125e4981a54c | 76 | T1.reset(); |
markus286 | 1:125e4981a54c | 77 | T1.start(); |
markus286 | 1:125e4981a54c | 78 | while(1){ |
markus286 | 1:125e4981a54c | 79 | |
markus286 | 1:125e4981a54c | 80 | if(T1.read() >= 0.2) { |
markus286 | 1:125e4981a54c | 81 | |
markus286 | 1:125e4981a54c | 82 | break; |
markus286 | 1:125e4981a54c | 83 | } |
markus286 | 1:125e4981a54c | 84 | |
markus286 | 1:125e4981a54c | 85 | else if(CheckFlag()){ |
markus286 | 1:125e4981a54c | 86 | T1.stop(); |
markus286 | 1:125e4981a54c | 87 | state = ST_ENDE; |
markus286 | 1:125e4981a54c | 88 | return; |
markus286 | 1:125e4981a54c | 89 | } |
markus286 | 1:125e4981a54c | 90 | } |
markus286 | 1:125e4981a54c | 91 | |
markus286 | 0:603870fc1af3 | 92 | state = ST_EIN; |
markus286 | 0:603870fc1af3 | 93 | |
markus286 | 0:603870fc1af3 | 94 | // exit |
markus286 | 1:125e4981a54c | 95 | T1.stop(); |
markus286 | 0:603870fc1af3 | 96 | return; |
markus286 | 0:603870fc1af3 | 97 | } |
markus286 | 0:603870fc1af3 | 98 | } |
markus286 | 0:603870fc1af3 | 99 | } |
markus286 | 0:603870fc1af3 | 100 | |
markus286 | 1:125e4981a54c | 101 | void ST_Ende (void) |
markus286 | 0:603870fc1af3 | 102 | { |
markus286 | 1:125e4981a54c | 103 | //Status auf LCD und Serielle |
markus286 | 1:125e4981a54c | 104 | lcd.cls(); // löscht LCD (clear screen) |
markus286 | 0:603870fc1af3 | 105 | lcd.locate(0,0); // x-position, y-position (x: 0-128; y: 0-32) |
markus286 | 1:125e4981a54c | 106 | lcd.printf("State: Ende"); |
markus286 | 1:125e4981a54c | 107 | printf("State: Ende"); |
markus286 | 1:125e4981a54c | 108 | wait_ms(300); |
markus286 | 1:125e4981a54c | 109 | return; |
markus286 | 0:603870fc1af3 | 110 | } |
markus286 | 0:603870fc1af3 | 111 | |
markus286 | 0:603870fc1af3 | 112 | void ST_Error (void) |
markus286 | 0:603870fc1af3 | 113 | { |
markus286 | 1:125e4981a54c | 114 | //Status auf LCD und Serielle |
markus286 | 1:125e4981a54c | 115 | lcd.cls(); // löscht LCD (clear screen) |
markus286 | 0:603870fc1af3 | 116 | lcd.locate(0,0); // x-position, y-position (x: 0-128; y: 0-32) |
markus286 | 1:125e4981a54c | 117 | lcd.printf("State: ERROR"); |
markus286 | 1:125e4981a54c | 118 | printf("State: ERROR"); |
markus286 | 0:603870fc1af3 | 119 | return; |
markus286 | 0:603870fc1af3 | 120 | } |
markus286 | 0:603870fc1af3 | 121 | |
markus286 | 0:603870fc1af3 | 122 | void stateMachine() |
markus286 | 0:603870fc1af3 | 123 | { |
markus286 | 0:603870fc1af3 | 124 | switch (state) |
markus286 | 0:603870fc1af3 | 125 | { |
markus286 | 0:603870fc1af3 | 126 | case ST_EIN: ST_Ein(); |
markus286 | 0:603870fc1af3 | 127 | break; |
markus286 | 1:125e4981a54c | 128 | case ST_AUS: ST_Aus(); |
markus286 | 0:603870fc1af3 | 129 | break; |
markus286 | 1:125e4981a54c | 130 | case ST_ENDE: ST_Ende(); |
markus286 | 1:125e4981a54c | 131 | break; |
markus286 | 1:125e4981a54c | 132 | default: ST_Error(); |
markus286 | 0:603870fc1af3 | 133 | break; |
markus286 | 0:603870fc1af3 | 134 | } |
markus286 | 0:603870fc1af3 | 135 | } |
markus286 | 0:603870fc1af3 | 136 | |
markus286 | 1:125e4981a54c | 137 | |
markus286 | 0:603870fc1af3 | 138 | |
markus286 | 0:603870fc1af3 | 139 | int main() |
markus286 | 0:603870fc1af3 | 140 | { |
markus286 | 1:125e4981a54c | 141 | btn.rise(&rise); |
markus286 | 1:125e4981a54c | 142 | |
markus286 | 1:125e4981a54c | 143 | Leds = 15; |
markus286 | 1:125e4981a54c | 144 | wait_ms(500); |
markus286 | 1:125e4981a54c | 145 | |
markus286 | 1:125e4981a54c | 146 | state = ST_EIN; |
markus286 | 0:603870fc1af3 | 147 | while(true){ |
markus286 | 0:603870fc1af3 | 148 | stateMachine(); |
markus286 | 0:603870fc1af3 | 149 | } |
markus286 | 1:125e4981a54c | 150 | } |