example program for Insporado. Using MTSAS DK board with SMC and Grove Sensor Shield. Communication with AT&T M2X platform
Diff: main.cpp
- Revision:
- 1:251634b26859
- Parent:
- 0:93ce3fa57a5e
--- 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 +}