Hello all friends, Im a student doing a Blynk project on Raspberry Pi by using Python. One part of the project is an automatic electric fan which is based on the temperature. I have used the blynk.set_user_task function to run the control part, but this function is actually a non-stop periodic function, currently I just used some if statements to avoid printing the result when I turn the electric fan off. Here is my question, is there any way to stop the set_user_task function?
Here is part of my code
##add auto switch in the ducntion so when auto on, reading, off, manul control
def my_user_task():
#print('loop')
if GPIO.input(19): ## GPIO pin 19 is connected to GPIO pin 26
humidity,temperature = Adafruit_DHT.read_retry(22, 4)
print('Action 2')
blynk.virtual_write(3, '{0:0.1f}'.format(temperature))
print(temperature)
blynk.virtual_write(5, '{0:0.1f}'.format(humidity))
print(humidity)
if temperature > 21.0:
GPIO.output(FAN_PIN, GPIO.LOW)
sleep(0.2)
else:
GPIO.output(FAN_PIN, GPIO.HIGH)
sleep(0.2)
@blynk.VIRTUAL_WRITE(1)
def my_write_handler(value): ## change only the input changed
if value == '1':
print(value)
GPIO.output(26, GPIO.HIGH)
blynk.set_user_task(my_user_task,10000)
elif value == '0':
GPIO.output(26, GPIO.LOW)
GPIO.output(FAN_PIN, GPIO.HIGH)