I'am quite new to micropython and working/playing with a esp32, trying to make an automatic door opener for a chicken coop.
I plan to use an oled screen and a rotary encoder to choose the time of opening, set the date, ...
I would like to put the esp32 in deepsleep mode after a certain time of inactivity, for example 1minute.
Here is my code dealing with the motor and the switches using uasyncio :
Code: Select all
import machine
import time
import esp32
import uasyncio as asyncio
from primitives.switch import Switch
motPWM = machine.PWM(machine.Pin(33), freq=50)
motPWM.freq(1000)
motDir = machine.Pin(32, machine.Pin.OUT)
dutyCycle = 512 #doit etre entre 0 and 1023
openButton = machine.Pin(4, machine.Pin.IN, machine.Pin.PULL_UP)
doorHigh = machine.Pin(18, machine.Pin.IN, machine.Pin.PULL_UP)
async def startMot () :
if not doorHigh.value() :
motDir.value(0) #deroulement garcette
motPWM.duty(dutyCycle)
await asyncio.sleep(0)
async def stopMot () :
motPWM.duty(0)
await asyncio.sleep(0)
async def dummy_app() :
await asyncio.sleep(0)
swOpen = Switch(openButton)
swHigh = Switch(doorHigh)
swOpen.close_func(startMot)
swHigh.close_func(stopMot)
while True :
asyncio.run(dummy_app())