Blinker

Dependencies:   TextLCD mbed MMA8451Q

Committer:
Berrng
Date:
Fri Jun 20 09:34:17 2014 +0000
Revision:
6:ee51f453cc7c
Parent:
5:c64c025a4993
Child:
7:c1d05f2830fb
erweiterung

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
Berrng 6:ee51f453cc7c 13 AnalogIn Panzer(PTB1);
Daniel90 4:a0a518132c23 14
Daniel90 4:a0a518132c23 15 #define NO_KEY 0 //definiert die Keys des LCD Shields
Daniel90 4:a0a518132c23 16 #define UP_KEY 1
Daniel90 4:a0a518132c23 17 #define DOWN_KEY 2
Daniel90 4:a0a518132c23 18 #define LEFT_KEY 3
Daniel90 4:a0a518132c23 19 #define RIGHT_KEY 4
Daniel90 4:a0a518132c23 20 #define SELECT_KEY 5
Daniel90 3:05c8449bc489 21
Daniel90 3:05c8449bc489 22 TextLCD lcd(PTA13, PTD5, PTA4, PTA5, PTC8, PTC9, TextLCD::LCD16x2); //Config. für das LCD Shield
Daniel90 4:a0a518132c23 23 int read_LCD_buttons();
Daniel90 4:a0a518132c23 24
Daniel90 3:05c8449bc489 25
Daniel90 3:05c8449bc489 26 int main()
Daniel90 3:05c8449bc489 27 {
Berrng 6:ee51f453cc7c 28 anfang:
Berrng 6:ee51f453cc7c 29 lcd.cls();
Berrng 6:ee51f453cc7c 30 BlinkerL= 1;
Berrng 6:ee51f453cc7c 31 while(1)
Berrng 6:ee51f453cc7c 32 {
Berrng 6:ee51f453cc7c 33 if (Panzer > 0.8)
Berrng 6:ee51f453cc7c 34 {
Berrng 6:ee51f453cc7c 35
Berrng 5:c64c025a4993 36 BlinkerR= 1;
Berrng 5:c64c025a4993 37 myLED_G= 0;
Berrng 5:c64c025a4993 38 wait(0.2);
Berrng 5:c64c025a4993 39 BlinkerR= 0;
Berrng 5:c64c025a4993 40 myLED_G= 1;
Berrng 5:c64c025a4993 41 wait(0.2);
Berrng 6:ee51f453cc7c 42 }
Berrng 6:ee51f453cc7c 43 else
Berrng 6:ee51f453cc7c 44 {
Berrng 6:ee51f453cc7c 45 goto anfang;
Berrng 6:ee51f453cc7c 46 }
Daniel90 3:05c8449bc489 47 }
Berrng 6:ee51f453cc7c 48 }
Daniel90 4:a0a518132c23 49 //Bestimmt, welche Taste gerade gedrückt wird
Daniel90 4:a0a518132c23 50 int read_LCD_KEYS()
Daniel90 4:a0a518132c23 51 {
Daniel90 4:a0a518132c23 52 int adc_key_in = 0;
Daniel90 4:a0a518132c23 53 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 54 // watch approching values for pushbutton and set table below
Daniel90 4:a0a518132c23 55 // add approx 500 for safety
Daniel90 4:a0a518132c23 56
Daniel90 4:a0a518132c23 57 if (adc_key_in > 65000) {return NO_KEY;}
Daniel90 4:a0a518132c23 58 if (adc_key_in < 50) {return RIGHT_KEY;}
Daniel90 4:a0a518132c23 59 //if (adc_key_in < 790) {return SELECT_KEY;}
Daniel90 4:a0a518132c23 60 if (adc_key_in < 15500) {return UP_KEY;}
Daniel90 4:a0a518132c23 61 if (adc_key_in < 34600) {return DOWN_KEY;}
Daniel90 4:a0a518132c23 62 if (adc_key_in < 54000) {return LEFT_KEY;}
Daniel90 4:a0a518132c23 63
Daniel90 4:a0a518132c23 64 return NO_KEY; //when no value readable, also return NO_KEY...
Daniel90 4:a0a518132c23 65 }
Daniel90 3:05c8449bc489 66 //Ende