Blinker

Dependencies:   TextLCD mbed MMA8451Q

Revision:
16:3775d1fa074b
Parent:
15:af1df0baba62
Child:
17:c96c9af96dbb
--- a/Blinker.cpp	Fri Jun 27 07:17:49 2014 +0000
+++ b/Blinker.cpp	Fri Jun 27 11:22:07 2014 +0000
@@ -4,17 +4,19 @@
 
 #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
+#include "TSISensor.h"                                                 //library für den TSi Sensor Idee: Helligkeit des Lichts einstellen
 
 
-DigitalOut myLED_G(PTB19);                                              // grüne LED auf dem Board
-DigitalOut myLED_R(PTB18);                                              // rote LED auf dem Board
-DigitalOut Blinker_L_Led(PTD1);                                       // Digitaler Ausgang für die Blinker links
-//DigitalOut Blinker_R_Led(PTD3);                                       // Digitaler Ausgang für die Blinker rechts
+DigitalOut Blinker_L_Led(PTD2);                                         // Digitaler Ausgang für die Blinker links
+DigitalOut Blinker_R_Led(PTD3);                                         // Digitaler Ausgang für die Blinker rechts
+DigitalOut Licht(PTA12);                                                 // Digitaler Ausgang für Licht
+//PwmOut Licht(PTD0);  
 
 AnalogIn KEYS(PTB0);                                                    //Analog In um die Spannung an PTB0 zu bestimmen und die Buttons zu erkennen
 TextLCD lcd(PTA13, PTD5, PTA4, PTA5, PTC8, PTC9, TextLCD::LCD16x2);     //Konfiguration des LCD-Keypad-Schields mit Pins: rs, e, d4, d5, d6, d7
 
+//TSISensor touchpad;
+
 #define RIGHT_KEY   0
 #define UP_KEY      1
 #define DOWN_KEY    2
@@ -25,24 +27,34 @@
 //Funktions Prototypen
 void Programmwahl();
 int read_KEY();
-float z = 0.4;                                                          //Blinkrythmus
+float z = 0.4;                                                         //Blinkrythmus
+float wt=0.4;                                                         
 int buttonState = 0;
 
 void BlinkerL();
-//void BlinkerR();
-//void BlinkerW();
-
+void BlinkerR();
+void BlinkerW();
+//void Slider();
 
 int main()
-{
-    Blinker_L_Led = 0;                                     
-    myLED_G= 1;
-    myLED_R= 1;
-    
+{   
+    //Licht = 1; 
+    //wait(0.1);                               
     lcd.cls();
+    lcd.locate(3,0);
+    lcd.printf("Welcome To");
     lcd.locate(4,1);
     lcd.printf("smartBIG");
-    
+    char h;
+        for (h=2; h>=1; h--)
+            {
+                Licht=0;
+                wait(0.2);
+                Licht=1;
+                wait(0.2);
+            }
+    wait(1);
+      
     Programmwahl();
 }
 
@@ -50,17 +62,27 @@
 
 void Programmwahl()
 {
+    Blinker_L_Led = 0;  
+    Blinker_R_Led = 0;
     lcd.cls();
     lcd.locate(4,1);
     lcd.printf("smartBIG");       
     while(1)
         {
-        wait(0.05);                                     // Wichtig!!! Richtige Zuordnung der Buttons
+        wait(wt);                                     // Wichtig!!! Richtige Zuordnung der Buttons
         buttonState = read_KEY();
         if (buttonState == LEFT_KEY)
         {
             BlinkerL();
         }
+        if (buttonState == RIGHT_KEY)
+        {
+            BlinkerR();
+        }
+        if (buttonState == UP_KEY)
+        {
+            BlinkerW();
+        }
     }
 }
 
@@ -76,8 +98,8 @@
     lcd.locate(0,0);
     lcd.printf("<--");
     Blinker_L_Led = 1;
+    wait(wt);
     buttonState = read_KEY();
-    wait(z);
     
         if (buttonState == LEFT_KEY)                // Einstieg Dauerblinker
         {   while(1)
@@ -96,16 +118,15 @@
                 lcd.locate(0,0);
                 lcd.printf("<--");
                 Blinker_L_Led = 1;
+                wait(wt);
                 buttonState = read_KEY();
-                wait(z);
                 
                 if (buttonState == DOWN_KEY)        // Abbruchbedingung Dauerblinker
                 {
-                Blinker_L_Led = 0;     
                 Programmwahl();
                 }
-                //if (buttonState == UP_KEY)        // Einstieg Warnblinker
-                //{ BlinkerW();}
+                if (buttonState == UP_KEY)        // Einstieg Warnblinker
+                { BlinkerW();}
             }   
         }
         else                                        //Kompfortblinker
@@ -128,7 +149,103 @@
             }
             Programmwahl();                                         // Zurück zur Programmwahl
             }
+
+
+// Programm für die Ansteuerung des rechten Blinker
+
+void BlinkerR()
+{
+    buttonState = NO_KEY;
+    lcd.cls();
+    lcd.locate(1,1);
+    lcd.printf("Blinker  Rechts");
+    wait(z);
+    lcd.locate(13,0);
+    lcd.printf("-->");
+    Blinker_R_Led = 1;
+    wait(wt);
+    buttonState = read_KEY();
     
+        if (buttonState == RIGHT_KEY)                // Einstieg Dauerblinker
+        {   while(1)
+            {
+                
+                /*buttonState = read_KEY();
+                wait(0.05);
+                if (buttonState == DOWN_KEY)        // Abbruchbedingung Dauerblinker
+                { Programmwahl();}*/
+                Blinker_R_Led = 0;
+                buttonState = NO_KEY;
+                lcd.cls();
+                lcd.locate(2,1);
+                lcd.printf("Dauerblinker");
+                wait(z);
+                lcd.locate(13,0);
+                lcd.printf("-->");
+                Blinker_R_Led = 1;
+                wait(wt);
+                buttonState = read_KEY();
+                
+                if (buttonState == DOWN_KEY)        // Abbruchbedingung Dauerblinker
+                {
+                Programmwahl();
+                }
+                if (buttonState == UP_KEY)        // Einstieg Warnblinker
+                { BlinkerW();}
+            }   
+        }
+        else                                        //Kompfortblinker
+            {
+            char x = 3;
+            for (x=3; x>=1; x--)
+            {
+                Blinker_R_Led = 0;
+                lcd.cls();
+                lcd.locate(1,1);
+                lcd.printf("Komfortblinker");
+                wait(z);
+                lcd.locate(0,0);
+                lcd.printf("%d",x);
+                lcd.locate(13,0);
+                lcd.printf("-->");
+                Blinker_R_Led = 1;
+                wait(z);
+            }
+            }
+            Programmwahl();                                         // Zurück zur Programmwahl
+            }
+
+// Programm für die Ansteuerung der Warnblinkroutine
+
+void BlinkerW()
+{
+     while(1){
+             buttonState = NO_KEY;
+             lcd.cls();
+             lcd.locate(2,1);
+             lcd.printf("Warnblinker!");
+             Blinker_L_Led = 0;
+             Blinker_R_Led = 0;
+             wait(z);
+             lcd.locate(13,0);
+             lcd.printf("-->");
+             lcd.locate(0,0);
+             lcd.printf("<--");
+             Blinker_L_Led = 1;
+             Blinker_R_Led = 1;
+             wait(wt);
+             buttonState = read_KEY();
+        if (buttonState==DOWN_KEY || buttonState==UP_KEY)
+        {
+        Programmwahl();
+        }
+}
+    /*if (buttonState == DOWN_KEY)        // Abbruchbedingung Dauerblinker
+        {
+        Programmwahl();
+        }
+    */
+}