Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import machine, esp32, time, gc
- from kody import remote_code
- def send(code, debounce_ms = 200, repeat = 1):
- global transmit, remote_code
- gc.collect()
- for i in range(repeat):
- transmit.write_pulses(remote_code[code][0], remote_code[code][1])
- print("[INFO]: Sent ==> %s" % code)
- time.sleep_ms(debounce_ms)
- def blink_led(repeat = 2, led_on = 0, led_off = 1):
- for i in range(repeat):
- led.value(led_on); time.sleep_ms(5)
- led.value(led_off); time.sleep_ms(60)
- def sleep():
- print("[INFO]: ~ Zzz... ~")
- gc.collect()
- time.sleep_ms(200)
- machine.lightsleep()
- print("[INFO]: ~ Ready ~")
- def keys_both():
- print("[INFO]: Resetuję ...")
- machine.reset()
- key_on = machine.Pin(26, machine.Pin.IN)
- key_off = machine.Pin(25, machine.Pin.IN)
- transmit = esp32.RMT(0, pin = machine.Pin(23, machine.Pin.OUT), clock_div = 80, idle_level = False)
- #led = machine.Pin(22, machine.Pin.OUT, value = 1)
- esp32.wake_on_ext1((key_on, key_off), level = esp32.WAKEUP_ANY_HIGH)
- print("[INFO]: ~ START ~")
- key_count = 0
- while True:
- if key_on.value() and key_off.value():
- print("[INFO]: Nacisnąłeś oba klawisze")
- if key_count == 4:
- keys_both()
- key_count += 1
- time.sleep(1)
- elif key_on.value():
- send("ON")
- elif key_off.value():
- send("OFF")
- else:
- key_count = 0
- sleep()
- """
- while key_on.value():
- send("ON")
- else:
- while key_off.value():
- send("OFF")
- #sleep()
- """
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement