Blinker

Dependencies:   TextLCD mbed MMA8451Q

Committer:
Daniel90
Date:
Fri Jun 27 07:17:49 2014 +0000
Revision:
15:af1df0baba62
Parent:
14:38a4ae533a01
Child:
16:3775d1fa074b
main Blinker_L_Led = 0;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Daniel90 3:05c8449bc489 1 //Multifunktionsblinker
Daniel90 3:05c8449bc489 2 //Hardware: Freescale FRDM KL25Z & SaintSmart LCD Keypad Shield
Daniel90 3:05c8449bc489 3 //Copyright: Andre Ehwein, Marcel Berrang, Daniel Knopp
Daniel90 3:05c8449bc489 4
Berrng 10:31d4d8104813 5 #include "mbed.h" //common library für mbed
Berrng 10:31d4d8104813 6 #include "TextLCD.h" //library für den LCD Shield
Berrng 10:31d4d8104813 7 #include "TSISensor.h" //library für den TSi Sensor Idee: Helligkeit der Blinker LEDs einstellen
Berrng 10:31d4d8104813 8
Daniel90 4:a0a518132c23 9
Berrng 10:31d4d8104813 10 DigitalOut myLED_G(PTB19); // grüne LED auf dem Board
Berrng 10:31d4d8104813 11 DigitalOut myLED_R(PTB18); // rote LED auf dem Board
Berrng 13:243a94718e51 12 DigitalOut Blinker_L_Led(PTD1); // Digitaler Ausgang für die Blinker links
Klaus89 12:601b595e68a0 13 //DigitalOut Blinker_R_Led(PTD3); // Digitaler Ausgang für die Blinker rechts
Berrng 11:f3de201aace6 14
Berrng 7:c1d05f2830fb 15 AnalogIn KEYS(PTB0); //Analog In um die Spannung an PTB0 zu bestimmen und die Buttons zu erkennen
Berrng 10:31d4d8104813 16 TextLCD lcd(PTA13, PTD5, PTA4, PTA5, PTC8, PTC9, TextLCD::LCD16x2); //Konfiguration des LCD-Keypad-Schields mit Pins: rs, e, d4, d5, d6, d7
Berrng 10:31d4d8104813 17
Berrng 11:f3de201aace6 18 #define RIGHT_KEY 0
Berrng 10:31d4d8104813 19 #define UP_KEY 1
Berrng 10:31d4d8104813 20 #define DOWN_KEY 2
Berrng 10:31d4d8104813 21 #define LEFT_KEY 3
Berrng 11:f3de201aace6 22 #define SELECT_KEY 4
Berrng 11:f3de201aace6 23 #define NO_KEY 5 //definiert die Keys des LCD Shields
Berrng 7:c1d05f2830fb 24
Berrng 10:31d4d8104813 25 //Funktions Prototypen
Berrng 10:31d4d8104813 26 void Programmwahl();
Berrng 10:31d4d8104813 27 int read_KEY();
Berrng 13:243a94718e51 28 float z = 0.4; //Blinkrythmus
Berrng 11:f3de201aace6 29 int buttonState = 0;
Berrng 10:31d4d8104813 30
Berrng 10:31d4d8104813 31 void BlinkerL();
Berrng 10:31d4d8104813 32 //void BlinkerR();
Berrng 10:31d4d8104813 33 //void BlinkerW();
Berrng 7:c1d05f2830fb 34
Berrng 11:f3de201aace6 35
Berrng 7:c1d05f2830fb 36 int main()
Berrng 7:c1d05f2830fb 37 {
Daniel90 15:af1df0baba62 38 Blinker_L_Led = 0;
Berrng 10:31d4d8104813 39 myLED_G= 1;
Berrng 10:31d4d8104813 40 myLED_R= 1;
Berrng 13:243a94718e51 41
Berrng 10:31d4d8104813 42 lcd.cls();
Berrng 10:31d4d8104813 43 lcd.locate(4,1);
Berrng 10:31d4d8104813 44 lcd.printf("smartBIG");
Berrng 10:31d4d8104813 45
Berrng 10:31d4d8104813 46 Programmwahl();
Berrng 10:31d4d8104813 47 }
Berrng 10:31d4d8104813 48
Berrng 10:31d4d8104813 49
Berrng 10:31d4d8104813 50
Berrng 10:31d4d8104813 51 void Programmwahl()
Berrng 10:31d4d8104813 52 {
Berrng 10:31d4d8104813 53 lcd.cls();
Berrng 10:31d4d8104813 54 lcd.locate(4,1);
Berrng 11:f3de201aace6 55 lcd.printf("smartBIG");
Berrng 10:31d4d8104813 56 while(1)
Berrng 10:31d4d8104813 57 {
Berrng 11:f3de201aace6 58 wait(0.05); // Wichtig!!! Richtige Zuordnung der Buttons
Berrng 11:f3de201aace6 59 buttonState = read_KEY();
Berrng 11:f3de201aace6 60 if (buttonState == LEFT_KEY)
Berrng 10:31d4d8104813 61 {
Berrng 10:31d4d8104813 62 BlinkerL();
Berrng 10:31d4d8104813 63 }
Berrng 10:31d4d8104813 64 }
Berrng 10:31d4d8104813 65 }
Berrng 10:31d4d8104813 66
Berrng 11:f3de201aace6 67 // Programm für die Ansteuerung der linken Blinker
Berrng 10:31d4d8104813 68
Berrng 10:31d4d8104813 69 void BlinkerL()
Berrng 10:31d4d8104813 70 {
Berrng 11:f3de201aace6 71 buttonState = NO_KEY;
Berrng 10:31d4d8104813 72 lcd.cls();
Berrng 13:243a94718e51 73 lcd.locate(1,1);
Berrng 13:243a94718e51 74 lcd.printf("Blinker Links");
Berrng 10:31d4d8104813 75 wait(z);
Berrng 11:f3de201aace6 76 lcd.locate(0,0);
Berrng 10:31d4d8104813 77 lcd.printf("<--");
Daniel90 14:38a4ae533a01 78 Blinker_L_Led = 1;
Berrng 11:f3de201aace6 79 buttonState = read_KEY();
Berrng 10:31d4d8104813 80 wait(z);
Berrng 11:f3de201aace6 81
Berrng 11:f3de201aace6 82 if (buttonState == LEFT_KEY) // Einstieg Dauerblinker
Berrng 11:f3de201aace6 83 { while(1)
Berrng 10:31d4d8104813 84 {
Berrng 13:243a94718e51 85
Berrng 13:243a94718e51 86 /*buttonState = read_KEY();
Berrng 13:243a94718e51 87 wait(0.05);
Klaus89 12:601b595e68a0 88 if (buttonState == DOWN_KEY) // Abbruchbedingung Dauerblinker
Klaus89 12:601b595e68a0 89 { Programmwahl();}*/
Daniel90 14:38a4ae533a01 90 Blinker_L_Led = 0;
Berrng 11:f3de201aace6 91 buttonState = NO_KEY;
Berrng 11:f3de201aace6 92 lcd.cls();
Berrng 13:243a94718e51 93 lcd.locate(2,1);
Berrng 13:243a94718e51 94 lcd.printf("Dauerblinker");
Berrng 11:f3de201aace6 95 wait(z);
Berrng 11:f3de201aace6 96 lcd.locate(0,0);
Berrng 11:f3de201aace6 97 lcd.printf("<--");
Daniel90 14:38a4ae533a01 98 Blinker_L_Led = 1;
Berrng 11:f3de201aace6 99 buttonState = read_KEY();
Berrng 11:f3de201aace6 100 wait(z);
Klaus89 12:601b595e68a0 101
Berrng 11:f3de201aace6 102 if (buttonState == DOWN_KEY) // Abbruchbedingung Dauerblinker
Daniel90 14:38a4ae533a01 103 {
Daniel90 14:38a4ae533a01 104 Blinker_L_Led = 0;
Daniel90 14:38a4ae533a01 105 Programmwahl();
Daniel90 14:38a4ae533a01 106 }
Berrng 11:f3de201aace6 107 //if (buttonState == UP_KEY) // Einstieg Warnblinker
Berrng 11:f3de201aace6 108 //{ BlinkerW();}
Berrng 11:f3de201aace6 109 }
Berrng 11:f3de201aace6 110 }
Berrng 10:31d4d8104813 111 else //Kompfortblinker
Berrng 10:31d4d8104813 112 {
Berrng 11:f3de201aace6 113 char x = 3;
Berrng 11:f3de201aace6 114 for (x=3; x>=1; x--)
Berrng 10:31d4d8104813 115 {
Daniel90 14:38a4ae533a01 116 Blinker_L_Led = 0;
Berrng 10:31d4d8104813 117 lcd.cls();
Berrng 13:243a94718e51 118 lcd.locate(1,1);
Berrng 13:243a94718e51 119 lcd.printf("Komfortblinker");
Berrng 10:31d4d8104813 120 wait(z);
Berrng 10:31d4d8104813 121 lcd.locate(15,0);
Daniel90 14:38a4ae533a01 122 lcd.printf("%d",x);
Berrng 11:f3de201aace6 123 lcd.locate(0,0);
Berrng 10:31d4d8104813 124 lcd.printf("<--");
Daniel90 14:38a4ae533a01 125 Blinker_L_Led = 1;
Berrng 10:31d4d8104813 126 wait(z);
Berrng 10:31d4d8104813 127 }
Berrng 10:31d4d8104813 128 }
Berrng 11:f3de201aace6 129 Programmwahl(); // Zurück zur Programmwahl
Berrng 10:31d4d8104813 130 }
Berrng 10:31d4d8104813 131
Berrng 10:31d4d8104813 132
Berrng 10:31d4d8104813 133
Berrng 10:31d4d8104813 134
Berrng 10:31d4d8104813 135 int read_KEY() //Bestimmt, welche Taste gerade gedrückt wird
Berrng 10:31d4d8104813 136 {
Berrng 10:31d4d8104813 137 int adc_key_in = 0;
Berrng 10:31d4d8104813 138 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].
Berrng 10:31d4d8104813 139 // watch approching values for pushbutton and set table below
Berrng 10:31d4d8104813 140 // add approx 500 for safety
Berrng 10:31d4d8104813 141 if (adc_key_in > 65000) {return NO_KEY;}
Berrng 10:31d4d8104813 142 if (adc_key_in < 50) {return RIGHT_KEY;}
Berrng 10:31d4d8104813 143 //if (adc_key_in < 790) {return SELECT_KEY;}
Berrng 11:f3de201aace6 144 if (adc_key_in < 15000) {return UP_KEY;}
Berrng 11:f3de201aace6 145 if (adc_key_in < 35000) {return DOWN_KEY;}
Berrng 11:f3de201aace6 146 if (adc_key_in < 53000) {return LEFT_KEY;}
Berrng 10:31d4d8104813 147
Berrng 10:31d4d8104813 148 return NO_KEY; //when no value readable, also return NO_KEY...
Berrng 10:31d4d8104813 149 }
Berrng 10:31d4d8104813 150
Daniel90 3:05c8449bc489 151 //Ende