Skip to content

Commit d1a57a7

Browse files
committed
Adding serial output for enhanced understanding.
1 parent 43c92de commit d1a57a7

File tree

3 files changed

+28
-15
lines changed

3 files changed

+28
-15
lines changed

examples/Threading_Basics/Thermostat/TemperatureControl_LivingRoom.inot

+7
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ int const LIVING_ROOM_HEATING_RELAY_PIN = 3;
55

66
void setup()
77
{
8+
Serial.begin(9600);
89
pinMode(LIVING_ROOM_HEATING_RELAY_PIN, OUTPUT);
910
}
1011

@@ -16,7 +17,13 @@ void loop()
1617
* on the heating.
1718
*/
1819
if (current_temperature_deg < 22.0f)
20+
{
1921
digitalWrite(LIVING_ROOM_HEATING_RELAY_PIN, HIGH);
22+
Serial.println("Living Room: Heating ON");
23+
}
2024
else
25+
{
2126
digitalWrite(LIVING_ROOM_HEATING_RELAY_PIN, LOW);
27+
Serial.println("Living Room: Heating OFF");
28+
}
2229
}
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,28 @@
11
/* Define a data sink named 'temperature' of type 'float'. */
22
SINK(temperature, float);
33

4+
int const SLEEPING_ROOM_AC_RELAY_PIN = 2;
5+
46
void setup()
57
{
6-
Serial.begin(9600);
8+
pinMode(SLEEPING_ROOM_AC_RELAY_PIN, OUTPUT);
79
}
810

911
void loop()
1012
{
1113
float current_temperature_deg = temperature.pop();
12-
Serial.print("Temperature = ");
13-
Serial.print(current_temperature_deg);
14-
Serial.println(" °C");
14+
/* Check if the temperature reported by the thermostat is above
15+
* or below 20.0 °C. If the temperature is above 20.0 °C, turn
16+
* on the AC.
17+
*/
18+
if (current_temperature_deg > 20.0f)
19+
{
20+
digitalWrite(SLEEPING_ROOM_AC_RELAY_PIN, HIGH);
21+
Serial.println("Sleeping Room: AC ON");
22+
}
23+
else
24+
{
25+
digitalWrite(SLEEPING_ROOM_AC_RELAY_PIN, LOW);
26+
Serial.println("Sleeping Room: AC OFF");
27+
}
1528
}
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,15 @@
11
/* Define a data sink named 'temperature' of type 'float'. */
22
SINK(temperature, float);
33

4-
int const SLEEPING_ROOM_AC_RELAY_PIN = 2;
5-
64
void setup()
75
{
8-
pinMode(SLEEPING_ROOM_AC_RELAY_PIN, OUTPUT);
6+
Serial.begin(9600);
97
}
108

119
void loop()
1210
{
1311
float current_temperature_deg = temperature.pop();
14-
/* Check if the temperature reported by the thermostat is above
15-
* or below 20.0 °C. If the temperature is above 20.0 °C, turn
16-
* on the AC.
17-
*/
18-
if (current_temperature_deg > 20.0f)
19-
digitalWrite(SLEEPING_ROOM_AC_RELAY_PIN, HIGH);
20-
else
21-
digitalWrite(SLEEPING_ROOM_AC_RELAY_PIN, LOW);
12+
Serial.print("Temperature = ");
13+
Serial.print(current_temperature_deg);
14+
Serial.println(" °C");
2215
}

0 commit comments

Comments
 (0)