File tree 4 files changed +10
-22
lines changed
examples/Threading_Basics/Thermostat
4 files changed +10
-22
lines changed 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, 10);
3
3
4
- static String sleeping_room_message_prefix(String const & /* msg */)
5
- {
6
- return String("[Sleeping Room] ");
7
- }
8
-
9
4
void setup()
10
5
{
11
6
Serial.begin(9600);
12
- Serial.prefix(sleeping_room_message_prefix);
13
7
while (!Serial) { }
14
8
}
15
9
@@ -20,13 +14,13 @@ void loop()
20
14
float current_temperature_deg = temperature.pop();
21
15
22
16
/* Check if the temperature reported by the thermostat is above
23
- * or below 20 .0 °C. If the temperature is above 20 .0 °C, turn
17
+ * or below 26 .0 °C. If the temperature is above 26 .0 °C, turn
24
18
* on the AC.
25
19
*/
26
20
bool turn_ac_on = false,
27
21
turn_ac_off = false;
28
22
29
- if (current_temperature_deg > 20 .0f)
23
+ if (current_temperature_deg > 26 .0f)
30
24
turn_ac_on = true;
31
25
else
32
26
turn_ac_off = true;
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, 10);
3
3
4
- static String living_room_message_prefix(String const & /* msg */)
5
- {
6
- return String("[Living Room] ");
7
- }
8
-
9
4
void setup()
10
5
{
11
6
Serial.begin(9600);
12
- Serial.prefix(living_room_message_prefix);
13
7
while (!Serial) { }
14
8
}
15
9
Original file line number Diff line number Diff line change @@ -9,9 +9,9 @@ void setup()
9
9
void loop()
10
10
{
11
11
/* Read temperature - since this is just a simulation
12
- * so we take a random value between 15 and 25 °C.
12
+ * so we take a random value between 15 and 30 °C.
13
13
*/
14
- float const temperature_deg = (rand() % 16) + 10 ;
14
+ float const temperature_deg = (rand() % 16) + 15 ;
15
15
/* Store in temperature source variable. */
16
16
temperature.push(temperature_deg);
17
17
/* Do only one temperature sensore measurement per second. */
Original file line number Diff line number Diff line change 14
14
15
15
void setup ()
16
16
{
17
- /* Connect the TemperatureSensor thread providing temperature readings
18
- * with the various TemperatureControl_* threads.
17
+ /* Connect the temperature sensor thread providing temperature readings
18
+ * with the various temperature control unit threads.
19
19
*/
20
- TemperatureSensor.temperature .connectTo (TemperatureControl_LivingRoom .temperature );
21
- TemperatureSensor.temperature .connectTo (TemperatureControl_SleepingRoom .temperature );
20
+ TemperatureSensor.temperature .connectTo (HeatingControl .temperature );
21
+ TemperatureSensor.temperature .connectTo (AirConditionerControl .temperature );
22
22
TemperatureSensor.temperature .connectTo (TemperatureSensorReporter.temperature );
23
23
24
24
/* Start the individual threads for sensing the temperature
25
25
* and controlling heating/air-conditioning based on the sensed
26
26
* temperature on a per-room basis.
27
27
*/
28
28
TemperatureSensor.start ();
29
- TemperatureControl_LivingRoom .start ();
30
- TemperatureControl_SleepingRoom .start ();
29
+ HeatingControl .start ();
30
+ AirConditionerControl .start ();
31
31
TemperatureSensorReporter.start ();
32
32
}
33
33
You can’t perform that action at this time.
0 commit comments