Advertisement
orborbson

remote_sender

Sep 18th, 2024 (edited)
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.41 KB | Source Code | 0 0
  1. import machine, esp32, time, gc
  2.    
  3. def send(code, debounce_ms = 500, repeat = 2):
  4.     global transmit, remote_code
  5.     for i in range(repeat):
  6.         transmit.write_pulses(remote_code[code][0], remote_code[code][1])
  7.     print("[INFO]: Sent ==> %s" % code)
  8.     time.sleep_ms(debounce_ms)
  9.    
  10. def blink_led(repeat = 2, led_on = 0, led_off = 1):
  11.     for i in range(repeat):
  12.         led.value(led_on); time.sleep_ms(5)
  13.         led.value(led_off); time.sleep_ms(60)
  14.        
  15. def sleep():
  16.     print("[INFO]: ~ Zzz... ~")
  17.     gc.collect()
  18.     time.sleep_ms(100)
  19.     machine.lightsleep()
  20.     print("[INFO]: ~ Ready ~")
  21.          
  22. key_on = machine.Pin(25, machine.Pin.IN)
  23. key_off = machine.Pin(26, machine.Pin.IN)
  24. transmit = esp32.RMT(0, pin = machine.Pin(23, machine.Pin.OUT), clock_div = 80, idle_level = False)
  25. #led = machine.Pin(22, machine.Pin.OUT, value = 1)
  26. esp32.wake_on_ext1((key_on, key_off), level = esp32.WAKEUP_ANY_HIGH)
  27.  
  28. remote_code = { "ON" : ([1092, 391, 1247, 399, 477, 1166, 1248, 398, 472, 1174, 1244, 399, 1245, 399, 1243, 401, 470, 1175, 1244, 401, 1243, 402, 1241, 405, 422, 1220, 425, 1225, 1236, 403, 428, 1216, 474, 1173, 426, 1219, 422, 1220, 425, 1222, 1237, 405, 1238, 413, 1232, 410, 1234, 408, 419, 12361, 1232, 414, 1230, 413, 419, 1229, 1229, 413, 414, 1233, 1228, 416, 1231, 413, 1275, 373, 407, 1236, 1229, 413, 1231, 416, 1225, 416, 414, 1234, 408, 1233, 1232, 413, 414, 1233, 407, 1236, 413, 1232, 410, 1233, 415, 1231, 1229, 413, 1227, 420, 1224, 419, 1224, 421, 407, 12368, 1225, 422, 1225, 423, 407, 1233, 1228, 417, 410, 1234, 1225, 418, 1227, 417, 1224, 421, 409, 1237, 1224, 421, 1224, 420, 1222, 422, 405, 1238, 410, 1234, 1270, 374, 411, 1236, 408, 1233, 410, 1236, 410, 1234, 411, 1235, 1221, 423, 1225, 420, 1222, 426, 1221, 416, 407, 12370, 1224, 422, 1225, 419, 407, 1237, 1224, 420, 404, 1239, 1224, 423, 1221, 419, 1225, 419, 411, 1236, 1222, 419, 1228, 419, 1221, 422, 407, 1236, 405, 1240, 1221, 425, 402, 1239, 410, 1235, 411, 1234, 405, 1240, 404, 1240, 1220, 421, 1222, 423, 1224, 421, 1224, 417, 408, 12370, 1222, 419, 1226, 419, 408, 1235, 1221, 426, 408, 1238, 1218, 422, 1226, 420, 1221, 421, 408, 1237, 1222, 420, 1224, 423, 1222, 423, 404, 1240, 404, 1239, 1223, 419, 407, 1237, 405, 1240, 408, 1234, 405, 1241, 407, 1238, 1218, 427, 1220, 422, 1223, 422, 1221, 417, 404, 12373, 1222, 422, 1224, 422, 408, 1233, 1270, 377, 404, 1237, 1221, 425, 1224, 419, 1222, 424, 406, 1236, 1219, 425, 1218, 426, 1218, 428, 405, 1237, 408, 1241, 1219, 422, 401, 1242, 405, 1239, 404, 1240, 404, 1240, 404, 1239, 1218, 425, 1225, 422, 1219, 422, 1224, 419, 405], True),
  29.                 "OFF": ([1005, 428, 1220, 422, 401, 1240, 405, 12366, 1226, 419, 1221, 422, 407, 1238, 1221, 423, 409, 1233, 1223, 419, 1225, 419, 1220, 425, 405, 1236, 1225, 421, 1219, 422, 1221, 425, 404, 1239, 405, 1240, 1218, 422, 408, 1238, 404, 1239, 404, 1241, 402, 1241, 402, 1238, 1220, 425, 1221, 423, 1216, 428, 404, 1234, 408, 12366, 1225, 419, 1219, 425, 408, 1237, 1220, 422, 404, 1238, 1225, 419, 1220, 425, 1221, 422, 405, 1238, 1221, 423, 1221, 422, 1223, 421, 402, 1242, 405, 1240, 1217, 425, 405, 1238, 403, 1239, 408, 1237, 405, 1238, 405, 1240, 1217, 426, 1220, 422, 1218, 426, 405, 1236, 402, 12368, 1224, 420, 1222, 421, 408, 1237, 1218, 425, 405, 1239, 1225, 419, 1219, 425, 1221, 422, 408, 1240, 1212, 425, 1222, 424, 1218, 425, 405, 1237, 401, 1242, 1219, 425, 405, 1240, 404, 1239, 405, 1237, 401, 1243, 402, 1243, 1219, 422, 1219, 425, 1222, 422, 405, 1237, 405, 12366, 1223, 423, 1221, 424, 405, 1237, 1219, 422, 408, 1238, 1223, 420, 1219, 427, 1221, 419, 407, 1237, 1221, 422, 1220, 425, 1220, 423, 408, 1235, 405, 1240, 1221, 423, 404, 1239, 404, 1240, 402, 1242, 404, 1238, 407, 1237, 1221, 422, 1223, 423, 1218, 423, 407, 1236, 403, 12371, 1221, 422, 1219, 425, 404, 1240, 1221, 422, 404, 1241, 1222, 421, 1219, 425, 1223, 419, 405, 1242, 1217, 424, 1217, 426, 1222, 421, 406, 1239, 404, 1241, 1216, 427, 405, 1237, 401, 1244, 405, 1237, 408, 1237, 404, 1239, 1217, 428, 1215, 428, 1219, 422, 407, 1234, 407, 12369, 1222, 419, 1224, 422, 405, 1236, 1223, 423, 405, 1239, 1219, 422, 1224, 423, 1221, 422, 404, 1237, 1222, 422, 1224, 421, 1221, 424, 399, 1244, 405, 1237, 1218, 430, 405, 1236, 405, 1237, 405, 1239, 404, 1240, 405, 1237, 1222], True)
  30.                 }
  31.  
  32. print("[INFO]: ~ START ~")
  33. while True:
  34.     while key_on.value():
  35.         send("ON")
  36.     else:
  37.         while key_off.value():
  38.             send("OFF")
  39.     sleep()
  40.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement