Martin Werluschnig
/
mbed_RGB_Ampel
main.cpp@0:f78e9c34f009, 2018-11-15 (annotated)
- Committer:
- martwerl
- Date:
- Thu Nov 15 18:03:05 2018 +0000
- Revision:
- 0:f78e9c34f009
mbed_RGB_Ampel
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
martwerl | 0:f78e9c34f009 | 1 | /* |
martwerl | 0:f78e9c34f009 | 2 | read string via rs232 and switch blue leds ... |
martwerl | 0:f78e9c34f009 | 3 | */ |
martwerl | 0:f78e9c34f009 | 4 | #include "mbed.h" |
martwerl | 0:f78e9c34f009 | 5 | |
martwerl | 0:f78e9c34f009 | 6 | #define rgbOFF 7 |
martwerl | 0:f78e9c34f009 | 7 | #define rgbRED 6 |
martwerl | 0:f78e9c34f009 | 8 | #define rgbBLUE 3 |
martwerl | 0:f78e9c34f009 | 9 | #define rgbYELLOW 4 |
martwerl | 0:f78e9c34f009 | 10 | // global vars and objects |
martwerl | 0:f78e9c34f009 | 11 | BusOut blueLeds(LED1, LED2, LED3, LED4); |
martwerl | 0:f78e9c34f009 | 12 | BusOut rgbLeds(p23, p24, p25); |
martwerl | 0:f78e9c34f009 | 13 | |
martwerl | 0:f78e9c34f009 | 14 | // functions |
martwerl | 0:f78e9c34f009 | 15 | |
martwerl | 0:f78e9c34f009 | 16 | int main() { |
martwerl | 0:f78e9c34f009 | 17 | int8_t cnt=0; // count var |
martwerl | 0:f78e9c34f009 | 18 | uint8_t countDirection = ' '; // Eingabevariable von der seriellen Schnittstelle |
martwerl | 0:f78e9c34f009 | 19 | int upCycles = 0, downCycles = 0; |
martwerl | 0:f78e9c34f009 | 20 | rgbLeds.write(rgbOFF); |
martwerl | 0:f78e9c34f009 | 21 | printf("mbed Uebung C - Bulme: Count Up and Down/SC\r\n"); |
martwerl | 0:f78e9c34f009 | 22 | |
martwerl | 0:f78e9c34f009 | 23 | while(1) { |
martwerl | 0:f78e9c34f009 | 24 | rgbLeds = rgbYELLOW; |
martwerl | 0:f78e9c34f009 | 25 | printf("\r\nZaehlrichtung auswaehlen: u --> aufwaerts zaehlen, d --> abwaehrts zaehlen;\r\nBitte um Eingabe: "); |
martwerl | 0:f78e9c34f009 | 26 | countDirection = getchar(); |
martwerl | 0:f78e9c34f009 | 27 | printf("Zaehlrichtung = %c", countDirection); |
martwerl | 0:f78e9c34f009 | 28 | if (countDirection == 'u') { |
martwerl | 0:f78e9c34f009 | 29 | rgbLeds = rgbBLUE; |
martwerl | 0:f78e9c34f009 | 30 | printf("\r\nCount UP: Aufwaertszaehlzyklus = %d\r\n", ++upCycles); |
martwerl | 0:f78e9c34f009 | 31 | for (cnt=0; cnt<=15; cnt++) { |
martwerl | 0:f78e9c34f009 | 32 | printf("Zaehlerstand = %d\r\n", cnt); |
martwerl | 0:f78e9c34f009 | 33 | blueLeds = cnt; |
martwerl | 0:f78e9c34f009 | 34 | wait(0.5); |
martwerl | 0:f78e9c34f009 | 35 | } |
martwerl | 0:f78e9c34f009 | 36 | } |
martwerl | 0:f78e9c34f009 | 37 | else if (countDirection == 'd') { |
martwerl | 0:f78e9c34f009 | 38 | downCycles++; |
martwerl | 0:f78e9c34f009 | 39 | rgbLeds = rgbRED; |
martwerl | 0:f78e9c34f009 | 40 | printf("\r\nCount DOWN: Abwaertszaehlzyklus = %d\r\n", downCycles); |
martwerl | 0:f78e9c34f009 | 41 | for (cnt=15; cnt>=0; cnt--) { |
martwerl | 0:f78e9c34f009 | 42 | printf("Zaehlerstand = %d\r\n", cnt); |
martwerl | 0:f78e9c34f009 | 43 | blueLeds.write(cnt); |
martwerl | 0:f78e9c34f009 | 44 | wait(0.5); |
martwerl | 0:f78e9c34f009 | 45 | } |
martwerl | 0:f78e9c34f009 | 46 | } |
martwerl | 0:f78e9c34f009 | 47 | else |
martwerl | 0:f78e9c34f009 | 48 | printf("\r\nmbed Uebung C: keine gueltige Eingabe fuer die Zaehlrichtung!\r\n"); |
martwerl | 0:f78e9c34f009 | 49 | } |
martwerl | 0:f78e9c34f009 | 50 | } |
martwerl | 0:f78e9c34f009 | 51 |