Blinky with temp

Fork of random-blinky by George Roussos

Files at this revision

API Documentation at this revision

Comitter:
gkroussos
Date:
Thu May 31 16:08:48 2018 +0000
Parent:
0:774078f45f9d
Commit message:
Blinks up according to temperature

Changed in this revision

img/uvision.png Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Thu May 31 15:33:24 2018 +0000
+++ b/main.cpp	Thu May 31 16:08:48 2018 +0000
@@ -4,16 +4,20 @@
 DigitalOut led2(LED2);
 DigitalOut led3(LED3);
 
+AnalogIn LM35(P0_2);
+
 // main() runs in its own thread in the OS
 // (note the calls to wait below for delays)
 int main() {
-    int myRandom; 
+    float myTemp; 
+    led1 = 0;
+    led2 = 0;
+    led3 = 0;
     while (true) {
-        myRandom = rand() % 100;
-        if (myRandom > 50) led1 = !led1;
-        led2 = !led2;
-        myRandom = rand() % 100;
-        if (myRandom > 50) led3 = !led3;
+        myTemp = ((LM35*3.3)-0.600)*100.0;
+        if (myTemp > 10.0) led1 = 1;
+        if (myTemp > 15.0) led2 = 1;
+        if (myTemp > 20.0) led3 = 1;
         wait(0.5);
     }
 }