A sample heatmap application on using the red and green LEDs and input from a temperature sensor

Dependencies:   DS1820 mbed

Committer:
gkroussos
Date:
Sat Jul 12 19:15:56 2014 +0000
Revision:
1:cc10d171a883
Parent:
0:f3a63f2e3746
Update for temperature sensor pin clash with LED3

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gkroussos 0:f3a63f2e3746 1 #include "mbed.h"
gkroussos 0:f3a63f2e3746 2 #include "DS1820.h"
gkroussos 0:f3a63f2e3746 3
gkroussos 1:cc10d171a883 4 #define DATA_PIN D12
gkroussos 0:f3a63f2e3746 5 #define minTemp 25.5
gkroussos 0:f3a63f2e3746 6 #define maxTemp 30.0
gkroussos 0:f3a63f2e3746 7
gkroussos 0:f3a63f2e3746 8
gkroussos 0:f3a63f2e3746 9 DS1820 probe(DATA_PIN);
gkroussos 0:f3a63f2e3746 10
gkroussos 0:f3a63f2e3746 11 PwmOut red(LED_RED);
gkroussos 0:f3a63f2e3746 12 PwmOut green(LED_GREEN);
gkroussos 0:f3a63f2e3746 13
gkroussos 0:f3a63f2e3746 14 int main() {
gkroussos 0:f3a63f2e3746 15 float p = 0.0;
gkroussos 0:f3a63f2e3746 16 red.period(0.001);
gkroussos 0:f3a63f2e3746 17
gkroussos 0:f3a63f2e3746 18 for (float i=0.0; i<1.0; i+= 0.25) {
gkroussos 0:f3a63f2e3746 19 green = i;
gkroussos 0:f3a63f2e3746 20 red = 1.0-i;
gkroussos 0:f3a63f2e3746 21 wait(2.0);
gkroussos 0:f3a63f2e3746 22 }
gkroussos 0:f3a63f2e3746 23
gkroussos 0:f3a63f2e3746 24 while (true) {
gkroussos 0:f3a63f2e3746 25 probe.convertTemperature(true, DS1820::all_devices); //Start temperature conversion, wait until ready
gkroussos 0:f3a63f2e3746 26 printf("It is %3.1foC\r\n", probe.temperature());
gkroussos 0:f3a63f2e3746 27 p = (probe.temperature() - minTemp) / (maxTemp - minTemp);
gkroussos 0:f3a63f2e3746 28 printf("LED Value %f\r\n", p);
gkroussos 0:f3a63f2e3746 29 green = p;
gkroussos 0:f3a63f2e3746 30 red = 1.0 -p;
gkroussos 0:f3a63f2e3746 31 wait (.5);
gkroussos 0:f3a63f2e3746 32 }
gkroussos 0:f3a63f2e3746 33 }