1
2
3char a;
4float voltage=0;
5float sensor=0;
6float celsius=0;
7float fahrenheit=0;
8float photocell=0;
9
10void setup() {
11 Serial.begin(9600);
12}
13
14void sendC()
15{
16 sensor=analogRead(0);
17 voltage=((sensor*5000)/1024);
18 voltage=voltage-500;
19 celsius=voltage/10;
20 Serial.println(" ");
21 Serial.print("Temperature: ");
22 Serial.print(celsius,2);
23 Serial.println(" degrees C");
24}
25
26void sendF()
27{
28 sensor=analogRead(0);
29 voltage=((sensor*5000)/1024);
30 voltage=voltage-500;
31 celsius=voltage/10;
32 fahrenheit=((celsius*1.8)+32);
33 Serial.println(" ");
34 Serial.print("Temperature: ");
35 Serial.print(fahrenheit,2);
36 Serial.println(" degrees F");
37}
38
39void getCommand()
40{
41 Serial.flush();
42 while (Serial.available() == 0)
43 {
44
45 }
46 while (Serial.available() > 0)
47 {
48 a = Serial.read();
49 }
50}
51
52void loop() {
53 getCommand();
54 switch (a)
55 {
56 case 'c':
57
58 sendC();
59 break;
60 case 'f':
61
62 sendF();
63 break;
64 }
65}