Blinker

Dependencies:   TextLCD mbed MMA8451Q

Blinker.cpp

Committer:
Daniel90
Date:
2014-06-19
Revision:
4:a0a518132c23
Parent:
3:05c8449bc489
Child:
5:c64c025a4993

File content as of revision 4:a0a518132c23:

//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 der Blinker LEDs einstellen

AnalogIn KEYS(PTB0);                                                 //Analog In um die Spannung an PTB0 zu bestimmen und die Buttons zu erkennen
DigitalOut myLED_G(PTB19);                                              //grüne LED Idee: stellt die grünen blinkenden Pfeile im Auto da

#define NO_KEY      0                                                   //definiert die Keys des LCD Shields
#define UP_KEY      1
#define DOWN_KEY    2
#define LEFT_KEY    3
#define RIGHT_KEY   4
#define SELECT_KEY  5

TextLCD lcd(PTA13, PTD5, PTA4, PTA5, PTC8, PTC9, TextLCD::LCD16x2);      //Config. für das LCD Shield
int read_LCD_buttons();


int main()
{
lcd.cls();    
}

//Bestimmt, welche Taste gerade gedrückt wird
int read_LCD_KEYS()
{   
    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 < 15500)    {return UP_KEY;}
    if (adc_key_in < 34600)    {return DOWN_KEY;}
    if (adc_key_in < 54000)    {return LEFT_KEY;}
      
    return NO_KEY;  //when no value readable, also return NO_KEY... 
} 
//Ende