Created
October 25, 2020 11:21
-
-
Save schedutron/53ea2691c683c14f5605d34cb41bdcac to your computer and use it in GitHub Desktop.
CircuitPlayground Express Code for Sending Power-on Signal to a class of Fujitsu General ACs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import array | |
import supervisor | |
import sys | |
import time | |
import pulseio | |
import board | |
from adafruit_circuitplayground import cp | |
# Set brightness level of LEDs on CPX | |
cp.pixels.brightness = 0.02 | |
# configure and initialize IR transmitter | |
PWM = pulseio.PWMOut(board.IR_TX, frequency = 38000, duty_cycle = 2 ** 15) | |
IR_OUT = pulseio.PulseOut(PWM) | |
IR_POWER_ON_SIG = array.array('H', [ | |
3353, 1566, 437, 388, 440, 388, 441, 1191, 435, 394, 435, 1196, 440, 389, | |
439, 390, 439, 399, 441, 1188, 437, 1195, 441, 388, 441, 392, 436, 388, 441, | |
1191, 435, 1197, 440, 398, 440, 385, 433, 510, 434, 394, 435, 394, 435, 393, | |
435, 393, 435, 394, 435, 403, 436, 389, 440, 388, 441, 388, 440, 388, 441, 1192, | |
433, 394, 436, 393, 434, 405, 435, 390, 439, 389, 440, 388, 439, 390, 439, 1192, | |
433, 397, 432, 397, 432, 407, 431, 392, 437, 1221, 436, 1196, 442, 1191, 433, | |
1199, 438, 1194, 442, 1190, 436, 1206, 441, 1188, 437, 392, 437, 391, 438, 1194, | |
442, 386, 443, 386, 442, 388, 441, 396, 434, 391, 436, 392, 437, 392, 441, 388, | |
437, 1195, 441, 1190, 435, 394, 436, 403, 435, 1194, 442, 385, 433, 396, 433, | |
396, 432, 396, 433, 395, 435, 394, 433, 1210, 441, 1187, 435, 393, 436, 393, 435, | |
394, 436, 391, 437, 392, 436, 393, 436, 405, 434, 1192, 434, 394, 435, 394, 434, | |
396, 433, 394, 435, 393, 436, 393, 435, 403, 437, 388, 440, 388, 440, 389, 440, | |
389, 440, 387, 442, 387, 441, 388, 440, 398, 441, 384, 436, 392, 435, 393, 440, | |
389, 437, 392, 437, 391, 437, 392, 436, 402, 438, 388, 440, 388, 441, 387, 442, | |
387, 441, 387, 442, 387, 443, 386, 442, 396, 432, 393, 436, 396, 432, 392, 437, | |
392, 436, 392, 437, 1197, 439, 388, 441, 398, 441, 1188, 438, 391, 438, 1193, 434, | |
1200, 435, 392, 437, 1195, 441, 388, 441, 395, 434 | |
]) # These are the power-on pulses for my AC, replace with your power-on signal | |
ON_CMD = 'on' | |
def power_on(): | |
IR_OUT.send(IR_POWER_ON_SIG) | |
cp.pixels[:] = [(0, 255, 0)] * 10 # light up all 10 LED's on board with green color | |
time.sleep(1) | |
cp.pixels[:] = [(0, 0, 0)] * 10 # turn LED's off again | |
def non_blocking_read(): | |
''' | |
This function receives bytes via USB and sanitizes them. | |
''' | |
signal_tokens = [] | |
s = '' | |
while supervisor.runtime.serial_bytes_available and s != '\n': | |
s = sys.stdin.read(1) | |
signal_tokens.append(s) | |
return ''.join(signal_tokens).strip() | |
while True: | |
cmd = non_blocking_read() | |
# if command sent over USB was 'on', send the pulses to the AC | |
if cmd == ON_CMD: | |
power_on() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment