![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Blinker
Dependencies: TextLCD mbed MMA8451Q
Blinker.cpp
- Committer:
- Daniel90
- Date:
- 2014-06-27
- Revision:
- 14:38a4ae533a01
- Parent:
- 13:243a94718e51
- Child:
- 15:af1df0baba62
File content as of revision 14:38a4ae533a01:
//Multifunktionsblinker //Hardware: Freescale FRDM KL25Z & SaintSmart LCD Keypad Shield //Copyright: Andre Ehwein, Marcel Berrang, Daniel Knopp #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 DigitalOut myLED_G(PTB19); // grüne LED auf dem Board DigitalOut myLED_R(PTB18); // rote LED auf dem Board DigitalOut Blinker_L_Led(PTD1); // Digitaler Ausgang für die Blinker links //DigitalOut Blinker_R_Led(PTD3); // Digitaler Ausgang für die Blinker rechts AnalogIn KEYS(PTB0); //Analog In um die Spannung an PTB0 zu bestimmen und die Buttons zu erkennen TextLCD lcd(PTA13, PTD5, PTA4, PTA5, PTC8, PTC9, TextLCD::LCD16x2); //Konfiguration des LCD-Keypad-Schields mit Pins: rs, e, d4, d5, d6, d7 #define RIGHT_KEY 0 #define UP_KEY 1 #define DOWN_KEY 2 #define LEFT_KEY 3 #define SELECT_KEY 4 #define NO_KEY 5 //definiert die Keys des LCD Shields //Funktions Prototypen void Programmwahl(); int read_KEY(); float z = 0.4; //Blinkrythmus int buttonState = 0; void BlinkerL(); //void BlinkerR(); //void BlinkerW(); int main() { myLED_G= 1; myLED_R= 1; lcd.cls(); lcd.locate(4,1); lcd.printf("smartBIG"); Programmwahl(); } void Programmwahl() { lcd.cls(); lcd.locate(4,1); lcd.printf("smartBIG"); while(1) { wait(0.05); // Wichtig!!! Richtige Zuordnung der Buttons buttonState = read_KEY(); if (buttonState == LEFT_KEY) { BlinkerL(); } } } // Programm für die Ansteuerung der linken Blinker void BlinkerL() { buttonState = NO_KEY; lcd.cls(); lcd.locate(1,1); lcd.printf("Blinker Links"); wait(z); lcd.locate(0,0); lcd.printf("<--"); Blinker_L_Led = 1; buttonState = read_KEY(); wait(z); if (buttonState == LEFT_KEY) // Einstieg Dauerblinker { while(1) { /*buttonState = read_KEY(); wait(0.05); if (buttonState == DOWN_KEY) // Abbruchbedingung Dauerblinker { Programmwahl();}*/ Blinker_L_Led = 0; buttonState = NO_KEY; lcd.cls(); lcd.locate(2,1); lcd.printf("Dauerblinker"); wait(z); lcd.locate(0,0); lcd.printf("<--"); Blinker_L_Led = 1; buttonState = read_KEY(); wait(z); if (buttonState == DOWN_KEY) // Abbruchbedingung Dauerblinker { Blinker_L_Led = 0; Programmwahl(); } //if (buttonState == UP_KEY) // Einstieg Warnblinker //{ BlinkerW();} } } else //Kompfortblinker { char x = 3; for (x=3; x>=1; x--) { Blinker_L_Led = 0; lcd.cls(); lcd.locate(1,1); lcd.printf("Komfortblinker"); wait(z); lcd.locate(15,0); lcd.printf("%d",x); lcd.locate(0,0); lcd.printf("<--"); Blinker_L_Led = 1; wait(z); } } Programmwahl(); // Zurück zur Programmwahl } int read_KEY() //Bestimmt, welche Taste gerade gedrückt wird { 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 if (adc_key_in > 65000) {return NO_KEY;} if (adc_key_in < 50) {return RIGHT_KEY;} //if (adc_key_in < 790) {return SELECT_KEY;} if (adc_key_in < 15000) {return UP_KEY;} if (adc_key_in < 35000) {return DOWN_KEY;} if (adc_key_in < 53000) {return LEFT_KEY;} return NO_KEY; //when no value readable, also return NO_KEY... } //Ende