Modifying the code
A skeleton has been provided in order to make it clearer what you need to code.
First modify the pins you are using for servo, sensor, and led socket:
LED_PIN = 8
TEMP_PIN = 0
SERVO_PIN = 5
The two main functions are BTfucntion()
and temperatureFunction()
, let's explain them:
BTfunction():
This function will be called every second and will get data received from bluetooth (phone, laptop). Depending on data received it will call another function to execute the action requested by the bluetooth device.
You can match data received with functions in dict functionInUse, as example we have a function getStatus() when 'get' is received from a bluetooth device.
TemperatureFunction():
This function also will be called every second and needs to read the temperature, adjust the servo's angle, and trigger the alarm if necessary.
Pro tips:
- We breakout the functions to be simple to implement, most of them are one liners.
- Try to first read temperature, you can always send the output to the screen.
- You won't need sleep,TemperatureFunction() will be called every second already.