Your BOB3 microcontroller has an integrated temperature sensor.
Now we're going to take the temperature sensor out for a drive:
The microcontroller measures the temperature. When being turned on, then BOB3s eyes are green.
If you warm the microcontroller, for example by using your finger, the temperature rises and the eyes turn red.
If, for example, you put BOB3 into the fridge, it'll be a bit colder and the eyes will turn blue.
In this example we're going to use one of the global variables:
A global variable is a variable that is available throughout he whole programme.
This is why we need to declare it outwith the setup funktion and outwith the loop!
Underneath the #include command, we're going to declare our global variable in line 4:
When turning BOB3 on, the temperature is measured in the
setup() funktion in line 11 and the value is stored in our global variable
Each time the
loop() function is run, the current temperature is measured in line 17 and stored in the local variable
The difference between the temperatures is calculated and stored in line 20.
In lines 22 to 28, the eyes' colours is controlled according to the temperature:
difference has a negative value if BOB3 turns colder than when he was turned on, for example if he's in the fridge.
difference has a positive value if BOB3 is warmer than when he was turned on.
If the current temperature is nearly equal to the temperature when he BOB3 was turned on, then they eyes are green.
- Compile and transfer
- Disconnect BOB3
- Remove the jumpers and reconnect them (BOB3 reset)
- The eyes should now light green.
- If BOB3 gets warmer, the eyes will turn red.
- If BOB3 gets colder, the eyes will turn blue.