Blinker
Dependencies: TextLCD mbed MMA8451Q
Blinker.cpp
- Committer:
- Berrng
- Date:
- 2014-06-27
- Revision:
- 16:3775d1fa074b
- Parent:
- 15:af1df0baba62
- Child:
- 17:c96c9af96dbb
File content as of revision 16:3775d1fa074b:
//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 des Lichts einstellen DigitalOut Blinker_L_Led(PTD2); // Digitaler Ausgang für die Blinker links DigitalOut Blinker_R_Led(PTD3); // Digitaler Ausgang für die Blinker rechts DigitalOut Licht(PTA12); // Digitaler Ausgang für Licht //PwmOut Licht(PTD0); 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 //TSISensor touchpad; #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 float wt=0.4; int buttonState = 0; void BlinkerL(); void BlinkerR(); void BlinkerW(); //void Slider(); int main() { //Licht = 1; //wait(0.1); lcd.cls(); lcd.locate(3,0); lcd.printf("Welcome To"); lcd.locate(4,1); lcd.printf("smartBIG"); char h; for (h=2; h>=1; h--) { Licht=0; wait(0.2); Licht=1; wait(0.2); } wait(1); Programmwahl(); } void Programmwahl() { Blinker_L_Led = 0; Blinker_R_Led = 0; lcd.cls(); lcd.locate(4,1); lcd.printf("smartBIG"); while(1) { wait(wt); // Wichtig!!! Richtige Zuordnung der Buttons buttonState = read_KEY(); if (buttonState == LEFT_KEY) { BlinkerL(); } if (buttonState == RIGHT_KEY) { BlinkerR(); } if (buttonState == UP_KEY) { BlinkerW(); } } } // 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; wait(wt); buttonState = read_KEY(); 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; wait(wt); buttonState = read_KEY(); if (buttonState == DOWN_KEY) // Abbruchbedingung Dauerblinker { 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 } // Programm für die Ansteuerung des rechten Blinker void BlinkerR() { buttonState = NO_KEY; lcd.cls(); lcd.locate(1,1); lcd.printf("Blinker Rechts"); wait(z); lcd.locate(13,0); lcd.printf("-->"); Blinker_R_Led = 1; wait(wt); buttonState = read_KEY(); if (buttonState == RIGHT_KEY) // Einstieg Dauerblinker { while(1) { /*buttonState = read_KEY(); wait(0.05); if (buttonState == DOWN_KEY) // Abbruchbedingung Dauerblinker { Programmwahl();}*/ Blinker_R_Led = 0; buttonState = NO_KEY; lcd.cls(); lcd.locate(2,1); lcd.printf("Dauerblinker"); wait(z); lcd.locate(13,0); lcd.printf("-->"); Blinker_R_Led = 1; wait(wt); buttonState = read_KEY(); if (buttonState == DOWN_KEY) // Abbruchbedingung Dauerblinker { Programmwahl(); } if (buttonState == UP_KEY) // Einstieg Warnblinker { BlinkerW();} } } else //Kompfortblinker { char x = 3; for (x=3; x>=1; x--) { Blinker_R_Led = 0; lcd.cls(); lcd.locate(1,1); lcd.printf("Komfortblinker"); wait(z); lcd.locate(0,0); lcd.printf("%d",x); lcd.locate(13,0); lcd.printf("-->"); Blinker_R_Led = 1; wait(z); } } Programmwahl(); // Zurück zur Programmwahl } // Programm für die Ansteuerung der Warnblinkroutine void BlinkerW() { while(1){ buttonState = NO_KEY; lcd.cls(); lcd.locate(2,1); lcd.printf("Warnblinker!"); Blinker_L_Led = 0; Blinker_R_Led = 0; wait(z); lcd.locate(13,0); lcd.printf("-->"); lcd.locate(0,0); lcd.printf("<--"); Blinker_L_Led = 1; Blinker_R_Led = 1; wait(wt); buttonState = read_KEY(); if (buttonState==DOWN_KEY || buttonState==UP_KEY) { Programmwahl(); } } /*if (buttonState == DOWN_KEY) // Abbruchbedingung Dauerblinker { 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