Blinker

Dependencies:   TextLCD mbed MMA8451Q

Committer:
Berrng
Date:
Fri Jun 20 08:50:49 2014 +0000
Revision:
5:c64c025a4993
Parent:
4:a0a518132c23
Child:
6:ee51f453cc7c
Bilkerbelegung und erstes Programm

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
Berrng 5:c64c025a4993 10 DigitalOut myLED_G(PTB19); //grüne LED Idee: stellt die grünen blinkenden Pfeile im Auto da
Berrng 5:c64c025a4993 11 DigitalOut BlinkerL(PTE0); // Digitaler Ausgang für die Bliker links
Berrng 5:c64c025a4993 12 DigitalOut BlinkerR(PTE1); // Digitaler Ausgang für die Bliker rechts
Daniel90 4:a0a518132c23 13
Daniel90 4:a0a518132c23 14 #define NO_KEY 0 //definiert die Keys des LCD Shields
Daniel90 4:a0a518132c23 15 #define UP_KEY 1
Daniel90 4:a0a518132c23 16 #define DOWN_KEY 2
Daniel90 4:a0a518132c23 17 #define LEFT_KEY 3
Daniel90 4:a0a518132c23 18 #define RIGHT_KEY 4
Daniel90 4:a0a518132c23 19 #define SELECT_KEY 5
Daniel90 3:05c8449bc489 20
Daniel90 3:05c8449bc489 21 TextLCD lcd(PTA13, PTD5, PTA4, PTA5, PTC8, PTC9, TextLCD::LCD16x2); //Config. für das LCD Shield
Daniel90 4:a0a518132c23 22 int read_LCD_buttons();
Daniel90 4:a0a518132c23 23
Daniel90 3:05c8449bc489 24
Daniel90 3:05c8449bc489 25 int main()
Daniel90 3:05c8449bc489 26 {
Berrng 5:c64c025a4993 27 lcd.cls();
Berrng 5:c64c025a4993 28 while(1) {
Berrng 5:c64c025a4993 29 BlinkerR= 1;
Berrng 5:c64c025a4993 30 myLED_G= 0;
Berrng 5:c64c025a4993 31 wait(0.2);
Berrng 5:c64c025a4993 32 BlinkerR= 0;
Berrng 5:c64c025a4993 33 myLED_G= 1;
Berrng 5:c64c025a4993 34 wait(0.2);
Berrng 5:c64c025a4993 35 }
Daniel90 3:05c8449bc489 36 }
Daniel90 3:05c8449bc489 37
Daniel90 4:a0a518132c23 38 //Bestimmt, welche Taste gerade gedrückt wird
Daniel90 4:a0a518132c23 39 int read_LCD_KEYS()
Daniel90 4:a0a518132c23 40 {
Daniel90 4:a0a518132c23 41 int adc_key_in = 0;
Daniel90 4:a0a518132c23 42 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 43 // watch approching values for pushbutton and set table below
Daniel90 4:a0a518132c23 44 // add approx 500 for safety
Daniel90 4:a0a518132c23 45
Daniel90 4:a0a518132c23 46 if (adc_key_in > 65000) {return NO_KEY;}
Daniel90 4:a0a518132c23 47 if (adc_key_in < 50) {return RIGHT_KEY;}
Daniel90 4:a0a518132c23 48 //if (adc_key_in < 790) {return SELECT_KEY;}
Daniel90 4:a0a518132c23 49 if (adc_key_in < 15500) {return UP_KEY;}
Daniel90 4:a0a518132c23 50 if (adc_key_in < 34600) {return DOWN_KEY;}
Daniel90 4:a0a518132c23 51 if (adc_key_in < 54000) {return LEFT_KEY;}
Daniel90 4:a0a518132c23 52
Daniel90 4:a0a518132c23 53 return NO_KEY; //when no value readable, also return NO_KEY...
Daniel90 4:a0a518132c23 54 }
Daniel90 3:05c8449bc489 55 //Ende