File tree 3 files changed +28
-15
lines changed
examples/Threading_Basics/Thermostat
3 files changed +28
-15
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ int const LIVING_ROOM_HEATING_RELAY_PIN = 3;
5
5
6
6
void setup()
7
7
{
8
+ Serial.begin(9600);
8
9
pinMode(LIVING_ROOM_HEATING_RELAY_PIN, OUTPUT);
9
10
}
10
11
@@ -16,7 +17,13 @@ void loop()
16
17
* on the heating.
17
18
*/
18
19
if (current_temperature_deg < 22.0f)
20
+ {
19
21
digitalWrite(LIVING_ROOM_HEATING_RELAY_PIN, HIGH);
22
+ Serial.println("Living Room: Heating ON");
23
+ }
20
24
else
25
+ {
21
26
digitalWrite(LIVING_ROOM_HEATING_RELAY_PIN, LOW);
27
+ Serial.println("Living Room: Heating OFF");
28
+ }
22
29
}
Original file line number Diff line number Diff line change 1
1
/* Define a data sink named 'temperature' of type 'float'. */
2
2
SINK(temperature, float);
3
3
4
+ int const SLEEPING_ROOM_AC_RELAY_PIN = 2;
5
+
4
6
void setup()
5
7
{
6
- Serial.begin(9600 );
8
+ pinMode(SLEEPING_ROOM_AC_RELAY_PIN, OUTPUT );
7
9
}
8
10
9
11
void loop()
10
12
{
11
13
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
+ }
15
28
}
Original file line number Diff line number Diff line change 1
1
/* Define a data sink named 'temperature' of type 'float'. */
2
2
SINK(temperature, float);
3
3
4
- int const SLEEPING_ROOM_AC_RELAY_PIN = 2;
5
-
6
4
void setup()
7
5
{
8
- pinMode(SLEEPING_ROOM_AC_RELAY_PIN, OUTPUT );
6
+ Serial.begin(9600 );
9
7
}
10
8
11
9
void loop()
12
10
{
13
11
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");
22
15
}
You can’t perform that action at this time.
0 commit comments