Blinker

Dependencies:   TextLCD mbed MMA8451Q

Committer:
Daniel90
Date:
Thu Jun 19 18:13:33 2014 +0000
Revision:
4:a0a518132c23
Parent:
3:05c8449bc489
Child:
5:c64c025a4993
?nderungen

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
Daniel90 3:05c8449bc489 5 #include "mbed.h" //common library für mbed
Daniel90 4:a0a518132c23 6 #include "TextLCD.h" //library für den LCD Shield
Daniel90 4:a0a518132c23 7 #include "TSISensor.h" //library für den TSi Sensor Idee: Helligkeit der Blinker LEDs einstellen
Daniel90 4:a0a518132c23 8
Daniel90 4:a0a518132c23 9 AnalogIn KEYS(PTB0); //Analog In um die Spannung an PTB0 zu bestimmen und die Buttons zu erkennen
Daniel90 4:a0a518132c23 10 DigitalOut myLED_G(PTB19); //grüne LED Idee: stellt die grünen blinkenden Pfeile im Auto da
Daniel90 4:a0a518132c23 11
Daniel90 4:a0a518132c23 12 #define NO_KEY 0 //definiert die Keys des LCD Shields
Daniel90 4:a0a518132c23 13 #define UP_KEY 1
Daniel90 4:a0a518132c23 14 #define DOWN_KEY 2
Daniel90 4:a0a518132c23 15 #define LEFT_KEY 3
Daniel90 4:a0a518132c23 16 #define RIGHT_KEY 4
Daniel90 4:a0a518132c23 17 #define SELECT_KEY 5
Daniel90 3:05c8449bc489 18
Daniel90 3:05c8449bc489 19 TextLCD lcd(PTA13, PTD5, PTA4, PTA5, PTC8, PTC9, TextLCD::LCD16x2); //Config. für das LCD Shield
Daniel90 4:a0a518132c23 20 int read_LCD_buttons();
Daniel90 4:a0a518132c23 21
Daniel90 3:05c8449bc489 22
Daniel90 3:05c8449bc489 23 int main()
Daniel90 3:05c8449bc489 24 {
Daniel90 3:05c8449bc489 25 lcd.cls();
Daniel90 3:05c8449bc489 26 }
Daniel90 3:05c8449bc489 27
Daniel90 4:a0a518132c23 28 //Bestimmt, welche Taste gerade gedrückt wird
Daniel90 4:a0a518132c23 29 int read_LCD_KEYS()
Daniel90 4:a0a518132c23 30 {
Daniel90 4:a0a518132c23 31 int adc_key_in = 0;
Daniel90 4:a0a518132c23 32 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].
Daniel90 4:a0a518132c23 33 // watch approching values for pushbutton and set table below
Daniel90 4:a0a518132c23 34 // add approx 500 for safety
Daniel90 4:a0a518132c23 35
Daniel90 4:a0a518132c23 36 if (adc_key_in > 65000) {return NO_KEY;}
Daniel90 4:a0a518132c23 37 if (adc_key_in < 50) {return RIGHT_KEY;}
Daniel90 4:a0a518132c23 38 //if (adc_key_in < 790) {return SELECT_KEY;}
Daniel90 4:a0a518132c23 39 if (adc_key_in < 15500) {return UP_KEY;}
Daniel90 4:a0a518132c23 40 if (adc_key_in < 34600) {return DOWN_KEY;}
Daniel90 4:a0a518132c23 41 if (adc_key_in < 54000) {return LEFT_KEY;}
Daniel90 4:a0a518132c23 42
Daniel90 4:a0a518132c23 43 return NO_KEY; //when no value readable, also return NO_KEY...
Daniel90 4:a0a518132c23 44 }
Daniel90 3:05c8449bc489 45 //Ende