example program for Insporado. Using MTSAS DK board with SMC and Grove Sensor Shield. Communication with AT&T M2X platform

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
mfiore
Date:
Tue Jan 27 21:51:30 2015 +0000
Parent:
0:93ce3fa57a5e
Commit message:
Add code to display temperature and turn on LED if lights are out

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Tue Jan 27 17:22:38 2015 +0000
+++ b/main.cpp	Tue Jan 27 21:51:30 2015 +0000
@@ -1,6 +1,44 @@
 #include "mbed.h"
 #include "mtsas.h"
 
-int main (void) {
+AnalogIn light(A0);
+AnalogIn temp(A1);
+DigitalOut led(D4);
+
+bool lights_on() {
+    float val = light.read();
+    if (val > 0.4f)
+        return true;
+    return false;
+}
+
+float get_temp_c() {
+    int beta = 3975;
+    int val = temp.read_u16();
+    float res = (float) 10000.0 * ((65536.0 / val) - 1.0);
+    float temp_c = (1 / ((log(res / 5000.0) / beta) + (1.0 / 298.15))) - 273.15 - 7;
+    
+    return temp_c;
+}
+
+float get_temp_f() {
+    float temp_f = get_temp_c() * 9 / 5 + 32;
+    
+    return temp_f;
+}
+
+int main() {
+    while (true) {
+        printf("temp: %f C\t %f F\r\n", get_temp_c(), get_temp_f());
+        if (lights_on()) {
+            printf("lights on!\r\n");
+            led = 0;
+        } else {
+            printf("lights off!\r\n");
+            led = 1;
+        }
+        wait(2);
+    }
+    
     return 0;
-}
\ No newline at end of file
+}