# This project is a starting point for an Infrared receiver
# The adafruit_irremote library drives this device!
# SPDX-FileCopyrightText: 2019 Anne Barela for Adafruit Industries
#
# SPDX-License-Identifier: MIT
import board
import pulseio
import pwmio
import array
import time
import digitalio
IR_OUT = board.A0
# Expected pulse, pasted in from previous recording REPL session:
PowerPulse = [8984, 4468, 590, 1661, 590, 1662, 589, 538, 589, 539, 589, 538,
589, 538, 589, 539, 589, 1662, 589, 1663, 588, 539, 589, 1662,
589, 539, 588, 1663, 588, 540, 587, 1664, 588, 540, 587, 540, 587,
540, 588, 540, 587, 540, 587, 1664, 587, 541, 586, 541, 587, 1665,
586, 1665, 586, 1665, 586, 1665, 586, 1666, 585, 542, 585, 1666,
585, 1666, 585, 543, 584]
print('IR: activated')
button_pin = board.GP15
button = digitalio.DigitalInOut(button_pin)
button.direction = digitalio.Direction.INPUT
button.pull = digitalio.Pull.DOWN
pulseOut = pulseio.PulseOut(IR_OUT)
while True:
if button.value:
time.sleep(1)
print("FIRING")
code = array.array('H', [PowerPulse[x] for x in range(len(PowerPulse))])
pulseOut.send(code)
#pulseOut.send(detected) # sends IR pulse
print("FIRED")
time.sleep(1)