Open 4.4Manual mode.py and click .
'''
* Filename : Manual mode
* Thonny : Thonny 4.1.4
* Auther : http//www.keyestudio.com
'''
from machine import Pin
import time
touch = Pin(2, Pin.IN)
INA = Pin(14, Pin.OUT)
INB = Pin(15, Pin.OUT)
press = 0
while True:
if touch.value() == 1 and press == 0:
INA.value(0)
INB.value(1)
press = 1
elif touch.value() == 1 and press == 1:
INA.value(0)
INB.value(0)
press = 0
time.sleep(0.1)
Conceive:
Initialization:
Set pins of the capacitive touch sensor and the 130 motor.
Define a variable press with an initial value of 0, which is used to control the state of motor.
Loop:
if touch.value() == 1 and press == 0:
INA.value(0)
INB.value(1)
press = 1
When the module is touched (touch.value() == 1
) and press = 0, the fan rotates and press will be assigned to value 1.
elif touch.value() == 1 and press == 1:
INA.value(0)
INB.value(0)
press = 0
When the module is touched (touch.value() == 1
) and press = 1, the fan stops working and press will be assigned to value 0.
Point: When we continuously touch the module, we need to know and control the state of the motor through the value of press.