def sleep_robot(): print('Time is up. Going to sleep') light_on(not Pin(o.right_eye).value(), None, pin=o.right_eye) play_audio(v.shutdown) utime.sleep(5) esp32.wake_on_touch(True) machine.deepsleep()
def set_sleep(timer): # Board enters deepsleep for 60 seconds # Can be woken up by: # - touching touchpad 2 (touchpad 1 has no effect) # - pressing either of the push button switches print("I am awake. Going to sleep for 1 minute.") led_red.value(0) esp32.wake_on_touch(True) esp32.wake_on_ext1(pins=(switch1, switch2), level=esp32.WAKEUP_ANY_HIGH) deepsleep(60000)
hardTimer.init(period=15000, mode=Timer.PERIODIC, callback=hardDispTime) # turn on/off green led def greenTouchSensor(timer): if greenTouch.read() < 300: led_green.on() else: led_green.off() #button wakeup esp32.wake_on_ext1(pins=(button1, button2), level=esp32.WAKEUP_ANY_HIGH) #touchpad wakeup redTouch.config(300) esp32.wake_on_touch(True) #deepsleep def deepsleep(timer): print("I am awake. Going to sleep for 1 minute") machine.deepsleep(60000) hardTimer3 = Timer(2) hardTimer3.init(period=30000, mode=Timer.PERIODIC, callback=deepsleep) hardTimer2 = Timer(1) hardTimer2.init(period=10, mode=Timer.PERIODIC, callback=greenTouchSensor)
#2.2.4 r_led = Pin(27, Pin.OUT) p1 = Pin(34, Pin.IN, Pin.PULL_DOWN) p2 = Pin(39, Pin.IN, Pin.PULL_DOWN) #When the board is awake, the red led is on r_led.value(1) slp = 0 #Make the board to sleep every 30s def toggle_slp(pin): global slp slp = 1 tim3 = Timer(3) tim3.init(period=30000, mode=1, callback=toggle_slp) #Final loop while True: g_led.value(g_tog) if (slp): print("I am awake. Going to sleep for 1 minute") t2.config(0) #Disable t2 esp32.wake_on_ext1((p1, p2), esp32.WAKEUP_ANY_HIGH) #Wake up due to push botton esp32.wake_on_touch(True) #Wake up due to touch pad machine.deepsleep(60000)
led_grn = Pin(17, Pin.OUT) led_red = Pin(16, Pin.OUT) led_red.value(1) t_0 = TouchPad(Pin(12)) t_1 = TouchPad(Pin(14)) #t_1.config(400) t_0.config(400) do_connect('Elite Longbowman', 'ageofempires') ntptime.settime() rtc = RTC() #ntptime.settime() esp32.wake_on_touch(t_0) esp32.wake_on_ext1(pins = (button_0, button_1), level = esp32.WAKEUP_ANY_HIGH) awake = {4: "Timer", 3: "Ext1", 5: "Touchpad"} #add for touchpad tim0 = Timer(0) tim0.init(period=15000, mode=Timer.PERIODIC, callback = lambda t: display())#15 tim1 = Timer(1) tim1.init(period=10, mode=Timer.PERIODIC, callback = lambda t: touched()) tim2 = Timer(2) tim2.init(period=30000, mode=Timer.PERIODIC, callback = lambda t: sleepy())#30 def display(): a = rtc.datetime() print("Date: " + ("%02d" % (a[1],)) + '/' + ("%02d" % (a[2],)) + '/' + ("%02d" % (a[0],))) print("Time: " + ("%02d" % ((a[4] - 4) % 24,)) + ":" + ("%02d" % (a[5],)) + ":" + ("%02d" % (a[6],)) + " HRS") def touched(): if t_1.read() < 400:
def init_sleep(): t = machine.TouchPad(machine.Pin(12)) # assign touch pin 14 to t t.config( 300) # configure the threshold at which the pin is considered touched esp32.wake_on_touch(True) # enable wake_on_touch return t