Blinker
Dependencies: TextLCD mbed MMA8451Q
Diff: Blinker.cpp
- Revision:
- 7:c1d05f2830fb
- Parent:
- 6:ee51f453cc7c
- Child:
- 8:6a4e86d75a00
--- a/Blinker.cpp Fri Jun 20 09:34:17 2014 +0000 +++ b/Blinker.cpp Fri Jun 20 13:49:49 2014 +0000 @@ -5,12 +5,70 @@ #include "mbed.h" //common library für mbed #include "TextLCD.h" //library für den LCD Shield #include "TSISensor.h" //library für den TSi Sensor Idee: Helligkeit der Blinker LEDs einstellen +#include "MMA8451Q.h" //library für den Beschleunigungssensor -AnalogIn KEYS(PTB0); //Analog In um die Spannung an PTB0 zu bestimmen und die Buttons zu erkennen -DigitalOut myLED_G(PTB19); //grüne LED Idee: stellt die grünen blinkenden Pfeile im Auto da -DigitalOut BlinkerL(PTE0); // Digitaler Ausgang für die Bliker links -DigitalOut BlinkerR(PTE1); // Digitaler Ausgang für die Bliker rechts -AnalogIn Panzer(PTB1); +AnalogIn KEYS(PTB0); //Analog In um die Spannung an PTB0 zu bestimmen und die Buttons zu erkennen +DigitalOut myLED_G(PTB19); //grüne LED Idee: stellt die grünen blinkenden Pfeile im Auto da +DigitalOut BlinkerL(PTE0); // Digitaler Ausgang für die Blinker links +DigitalOut BlinkerR(PTE1); // Digitaler Ausgang für die Blinker rechts +AnalogIn TasterS(PTB3); // Tster zum Rückstelen der Blinker +AnalogIn TasterL(PTB2); // Taster für Blinker links +AnalogIn TasterR(PTB1); // Taster für Blinker rechts + + + +int main() +{ +anfang: +int x = 0; //Zählvariable für Blinker-Schleife +float z = 0.4; +myLED_G= 1; + +while(1) +{ +if (TasterR > 0.8) + { + + BlinkerR= 1; + myLED_G= 0; + wait(z); + BlinkerR= 0; + myLED_G= 1; + wait(z); + if (TasterR > 0.8) + { + SchleifeR: + BlinkerR= 1; + myLED_G= 0; + wait(z); + BlinkerR= 0; + myLED_G= 1; + wait(z); + if (TasterS > 0.8) //Abschaltbedingung + {goto anfang;} + else { + goto SchleifeR; } + } + else //Kompfortblinker + {for (x=0; x<=2; x++) + {BlinkerR= 1; + myLED_G= 0; + wait(z); + BlinkerR= 0; + myLED_G= 1; + wait(z); + }} + + + } +else + { + goto anfang; + } +} +} + + #define NO_KEY 0 //definiert die Keys des LCD Shields #define UP_KEY 1 @@ -19,41 +77,14 @@ #define RIGHT_KEY 4 #define SELECT_KEY 5 -TextLCD lcd(PTA13, PTD5, PTA4, PTA5, PTC8, PTC9, TextLCD::LCD16x2); //Config. für das LCD Shield -int read_LCD_buttons(); - - -int main() -{ -anfang: -lcd.cls(); -BlinkerL= 1; -while(1) -{ -if (Panzer > 0.8) - { - - BlinkerR= 1; - myLED_G= 0; - wait(0.2); - BlinkerR= 0; - myLED_G= 1; - wait(0.2); - } -else - { - goto anfang; - } -} -} -//Bestimmt, welche Taste gerade gedrückt wird -int read_LCD_KEYS() +TextLCD lcd(PTA13, PTD5, PTA4, PTA5, PTC8, PTC9, TextLCD::LCD16x2); //Konfiguration für das LCD Shield +int read_LCD_KEYS() //Bestimmt, welche Taste gerade gedrückt wird +// lcd.cls(); { int adc_key_in = 0; - adc_key_in = KEYS.read_u16 (); // read the value from the sensor //Read the input voltage, represented as an unsigned short in the range [0x0, 0xFFFF]. - // watch approching values for pushbutton and set table below - // add approx 500 for safety - + adc_key_in = KEYS.read_u16 (); // read the value from the sensor //Read the input voltage, represented as an unsigned short in the range [0x0, 0xFFFF]. + // watch approching values for pushbutton and set table below + // add approx 500 for safety if (adc_key_in > 65000) {return NO_KEY;} if (adc_key_in < 50) {return RIGHT_KEY;} //if (adc_key_in < 790) {return SELECT_KEY;}