Advertisement
orborbson

wysyłanie kodów 433 mhz z pliku

Sep 28th, 2024 (edited)
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.64 KB | Source Code | 0 0
  1. import machine, esp32, time, gc
  2. from kody import remote_code
  3.    
  4. def send(code, debounce_ms = 200, repeat = 1):
  5.     global transmit, remote_code
  6.     gc.collect()
  7.     for i in range(repeat):
  8.         transmit.write_pulses(remote_code[code][0], remote_code[code][1])
  9.     print("[INFO]: Sent ==> %s" % code)
  10.     time.sleep_ms(debounce_ms)
  11.    
  12. def blink_led(repeat = 2, led_on = 0, led_off = 1):
  13.     for i in range(repeat):
  14.         led.value(led_on); time.sleep_ms(5)
  15.         led.value(led_off); time.sleep_ms(60)
  16.        
  17. def sleep():
  18.     print("[INFO]: ~ Zzz... ~")
  19.     gc.collect()
  20.     time.sleep_ms(200)
  21.     machine.lightsleep()
  22.     print("[INFO]: ~ Ready ~")
  23.    
  24. def keys_both():
  25.     print("[INFO]: Resetuję ...")
  26.     machine.reset()
  27.          
  28. key_on = machine.Pin(26, machine.Pin.IN)
  29. key_off = machine.Pin(25, machine.Pin.IN)
  30. transmit = esp32.RMT(0, pin = machine.Pin(23, machine.Pin.OUT), clock_div = 80, idle_level = False)
  31. #led = machine.Pin(22, machine.Pin.OUT, value = 1)
  32. esp32.wake_on_ext1((key_on, key_off), level = esp32.WAKEUP_ANY_HIGH)
  33.  
  34. print("[INFO]: ~ START ~")
  35. key_count = 0
  36.  
  37. while True:
  38.     if key_on.value() and key_off.value():
  39.         print("[INFO]: Nacisnąłeś oba klawisze")
  40.         if key_count == 4:
  41.             keys_both()
  42.         key_count += 1
  43.         time.sleep(1)
  44.     elif key_on.value():
  45.         send("ON")
  46.     elif key_off.value():
  47.         send("OFF")
  48.     else:
  49.         key_count = 0
  50.         sleep()
  51.            
  52.         """
  53.        while key_on.value():
  54.            send("ON")
  55.        else:
  56.            while key_off.value():
  57.                send("OFF")
  58.        #sleep()
  59.                """
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement