PWM_Modulation LED

Dependencies:   TextLCD mbed

Revision:
0:42f712bdf324
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue May 14 08:10:57 2013 +0000
@@ -0,0 +1,80 @@
+#include "mbed.h"
+#include "TextLCD.h"
+//#include "pwmled.h"
+Ticker systick;
+Ticker resetrut;
+
+volatile char bstandby;
+PwmOut led(LED1);
+DigitalIn hell(p10);
+DigitalIn dunk(p11);
+TextLCD lcd(p15, p16, p17, p18, p19, p20);
+int zahler;
+int zahleroff;
+
+//==================================================00
+void vTimer(void){
+
+bstandby =1;}
+//====================================
+void reset(void){
+    if(hell==0 || dunk==0){ zahler = 0; zahleroff = 0;}
+}
+//===================================================
+int main() {
+float pulsw;
+//void (*p)();
+pulsw = 0.5;
+zahler =0 ; // Zähler wieviel mal die systemzeit durchgelaufen ist. 
+zahleroff =0;
+bool on=0;
+//led = pulsw;
+ systick.attach(&vTimer, 0.037);
+ resetrut.attach(&reset, 1);
+    while(1) {
+    //============================================0
+    if(hell){
+    
+   if(on){ 
+        if(!dunk){
+        lcd.locate(0,0);
+        lcd.printf("HELL PRESS");
+        if(pulsw <= 0.98){
+            pulsw+= 0.01;
+            led = pulsw;}
+            }
+        }else{                                  // EINSCHALTRUTINE !!!!!!
+            if(dunk){
+            if(zahler == 10){on = 1 ; led = pulsw; zahler = 0;}
+            else zahler +=1;
+            }
+        }
+    }
+    //===============================================0
+    if(dunk){
+    if(on){
+        if(hell){                               // ausschaltrutine !!!!!
+            if(zahleroff == 10 ){ on = 0; led =0; zahleroff = 0;}
+            else zahleroff +=1;
+            }else{
+                 lcd.locate(0,0);
+                 lcd.printf("DUNK PRESS");
+                 if(pulsw >= 0.02){
+                    pulsw -= 0.01;
+                     led = pulsw;
+                        }
+              }
+        }
+    }
+    //====================================================
+ //  lcd.cls();
+ lcd.locate(0,1);
+ lcd.printf("%f",pulsw);
+ lcd.locate(9,1);
+ lcd.printf("%d",zahler);
+ lcd.locate(13,1);
+ lcd.printf("%d",zahleroff);
+     while(bstandby == 0) {};
+     bstandby = 0;
+    }
+}