Sequence LEDs

Dependencies:   TextLCD mbed

Fork of Y_01 by Yoshiyuki Takahashi

Files at this revision

API Documentation at this revision

Comitter:
seethe
Date:
Wed Feb 18 06:44:13 2015 +0000
Parent:
1:80eb2d3e5974
Commit message:
SinWave

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 80eb2d3e5974 -r ce41adf02350 main.cpp
--- a/main.cpp	Wed Feb 18 05:21:23 2015 +0000
+++ b/main.cpp	Wed Feb 18 06:44:13 2015 +0000
@@ -3,6 +3,8 @@
 #include "mbed.h"
 #include "TextLCD.h"
 
+#define     PI      3.1415
+
 //TextLCD lcd(p15, p16, p17, p18, p19, p20); // rs, e, d4-d7
 TextLCD lcd(p24, p26, p27, p28, p29, p30); // rs, e, d4-d7
 AnalogIn    in1(p15);
@@ -23,23 +25,25 @@
 
 int main() {
     int     nCnt;
-    double  cnt;
+    double  rad;
+    double  od;
     
     nCnt  = 0;
-    cnt = 0.1;
+    rad = 0.0;
     while(1){
         led_blink(nCnt);
         nCnt++;
         if(nCnt > 3)
            nCnt = 0;
            
-        wait(0.1);
-        sin(1);
-        cnt+=0.1;
-        if(cnt>=1.0)
-          cnt = 0.1;
-        out.write((float)cnt);
-        lcd.printf("...\n");
+        wait(0.01);
+        
+        od = sin(rad);
+        rad += 0.01;
+        if(rad>(2*PI))
+          rad = 0.0;
+        out.write((float)(0.5*od+0.5));
+        lcd.printf("%.3f\n", od);
         lcd.printf("%.2f,.%.2f,%.2f\n", in1.read(), in2.read(), in3.read());
     }
 }