Пример #1
0
def test_ir_transmit():
    global ir_transmitter, ir_transmitter_pwm, key_pressed_dict, remote_programming_dict

    # print("Transmitting IR")

    # only process if there are any keys in the dictionary
    if key_pressed_dict:
        # get the all of the keys in the dictionary that are being pressed
        # but from those, only take the first one
        pressed_key = list(key_pressed_dict.keys())[0]

        # proceed if we got a key pressed
        if pressed_key:
            # proceed if we've saved any programmed keys to dictionary
            if remote_programming_dict:
                # if we've saved the key that's being pressed as a programmed key, continue
                if pressed_key in remote_programming_dict:
                    # get the key from the dictionary that has the keys we've programmed
                    programmed_key = remote_programming_dict.get(pressed_key)

                    # create pulse from pwm
                    pulse = pulseio.PulseOut(ir_transmitter_pwm)

                    # get the ir code to transmit from the key we've pressed
                    remote_key_code = programmed_key["code"]

                    # transmit the pulse with the code as the data
                    ir_transmitter.transmit(pulse,
                                            array.array('H', remote_key_code))

                    print("Sent Remote IR Code - Key: {}, Code: {}".format(
                        pressed_key, remote_key_code))

    # wait a bit between transmitting
    time.sleep(0.2)
Пример #2
0
def test_ir_transmit():
    global ir_transmitter, OKAY

    test_pulse = pulseio.PulseOut(ir_transmitter_pwm)
    remote.transmit(test_pulse, OKAY)

    print("Sent Test IR Signal!", OKAY)
    time.sleep(0.2)
Пример #3
0
 def enableIROut(self, kHz):
     self.extent = 0
     self.irPWM = pulseio.PWMOut(self.outPin,
                                 frequency=kHz * 1000,
                                 duty_cycle=0)
     self.irSend = pulseio.PulseOut(self.irPWM)
     self.irPWM.duty_cycle = (2**16) // 3
     self.sendBuffer = array.array('H')
     time.sleep(0.4)
Пример #4
0
from adafruit_circuitplayground import cp
import board
import time
import pulseio
import array

# create IR input, maximum of 100 bits.
pulseIn = pulseio.PulseIn(board.IR_RX, maxlen=100, idle_state=True)
# clears any artifacts
pulseIn.clear()
pulseIn.resume()

# creates IR output pulse
pwm = pulseio.PWMOut(board.IR_TX, frequency=38000, duty_cycle=2 ** 15)
pulseOut = pulseio.PulseOut(pwm)

# array for pulse, this is the same pulse output when button a is pressed
# inputs are compared against this same array
# array.array('H'', [x]) must be used for IR pulse arrays when using pulseio
# indented to multiple lines so its easier to see
pulseArrayFan = array.array('H', [1296, 377, 1289, 384, 464, 1219, 1296, 379,
    1287, 394, 464, 1226, 461, 1229, 458, 1233, 464, 1226, 462, 1229, 456, 1232,
    1293, 6922, 1294, 379, 1287, 385, 463, 1220, 1295, 379, 1287, 395, 464,
    1225, 461, 1229, 458, 1232, 465, 1225, 462, 1229, 457, 1231, 1294, 6904, 1291,
    382, 1295, 377, 461, 1221, 1294, 380, 1296, 385, 464, 1226, 460, 1230, 457,
    1233, 464, 1234, 453, 1229, 457, 1230, 1295, 6918, 1287, 386, 1291, 381, 457,
    1225, 1289, 385, 1292, 388, 460, 1230, 457, 1232, 465, 1225, 462, 1228, 458,
    1232, 465, 1222, 1293, 6905, 1290, 382, 1295, 377, 461, 1221, 1293, 387, 1290,
    384, 464, 1225, 461, 1229, 458, 1231, 466, 1224, 463, 1226, 460, 1228, 1286, 6920,
    1296, 377, 1289, 382, 466, 1216, 1288, 386, 1291, 390, 458, 1231, 456, 1233, 464,
    1226, 460, 1229, 458, 1232, 465, 1222, 1292, 6904, 1291, 382, 1295, 376, 462, 1220,
# SPDX-License-Identifier: MIT

import time
import board
import pulseio
import adafruit_irremote
import neopixel

# Configure treasure information
TREASURE_ID = 1      # CHANGE THIS NUMBER TO 2, 3, ETC, A UNIQUE NUMBER FOR EACH TREASURE!
TRANSMIT_DELAY = 15  # change this as desired to affect game dynamics, or just leave as is

# Create NeoPixel object to indicate status
pixels = neopixel.NeoPixel(board.NEOPIXEL, 10)

# Create a 'pulseio' output, to send infrared signals on the IR transmitter @ 38KHz
pulseout = pulseio.PulseOut(board.IR_TX, frequency=38000, duty_cycle=2 ** 15)

# Create an encoder that will take numbers and turn them into IR pulses
encoder = adafruit_irremote.GenericTransmit(header=[9500, 4500],
                                            one=[550, 550],
                                            zero=[550, 1700],
                                            trail=0)

while True:
    pixels.fill(0xFF0000)
    encoder.transmit(pulseout, [TREASURE_ID]*4)
    time.sleep(0.25)
    pixels.fill(0)
    time.sleep(TRANSMIT_DELAY)
Пример #6
0
}


def encode_message(msg):
    words = msg.split(' ')
    message_buffer = []
    for word in words:
        message_buffer.extend([
            8000,
            8000,
        ])  # Indicates a new word.
        for character in word:
            message_buffer.extend([4000])  # Indicates a new letter.
            for val in MORSE_CODE_LOOKUP[character]:
                if val == '-':
                    message_buffer.extend([2000])  # Indicates a dah.
                else:
                    message_buffer.extend([1000])  # Indicates a dit.
    if words:
        message_buffer.extend([
            8000,
            8000,
        ])  # Indicates end of message
    return array.array('H', message_buffer)


ir_led = pulseio.PWMOut(board.REMOTEOUT, frequency=38000, duty_cycle=2**15)
ir_out = pulseio.PulseOut(ir_led)
message = encode_message("HELLO WORLD")
ir_out.send(message)
Пример #7
0
import time
import pulseio
import pwmio
import board
import adafruit_irremote
from adafruit_circuitplayground import cp

# Create a 'pwmio' output, to send infrared signals from the IR transmitter
try:
    pwm = pwmio.PWMOut(board.IR_TX, frequency=38000, duty_cycle=2**15)
except AttributeError as err:
    raise NotImplementedError(
        "This example does not work with Circuit Playground Bluefruit!"
    ) from err

pulseout = pulseio.PulseOut(pwm)  # pylint: disable=no-member
# Create an encoder that will take numbers and turn them into NEC IR pulses
encoder = adafruit_irremote.GenericTransmit(header=[9500, 4500],
                                            one=[550, 550],
                                            zero=[550, 1700],
                                            trail=0)

while True:
    if cp.button_a:
        print("Button A pressed! \n")
        cp.red_led = True
        encoder.transmit(pulseout, [66, 84, 78, 65])
        cp.red_led = False
        # wait so the receiver can get the full message
        time.sleep(0.2)
    if cp.button_b:
### by reduced with the left button and increased with the right button

import time

import pulseio
import board
import adafruit_irremote
from adafruit_circuitplayground import cp


### 40kHz modulation (for Sony) with 20% duty cycle
CARRIER_IRFREQ_SONY = 40 * 1000
ir_carrier_pwm = pulseio.PWMOut(board.IR_TX,
                                frequency=CARRIER_IRFREQ_SONY,
                                duty_cycle=round(20 / 100 * 65535))
ir_pulseout = pulseio.PulseOut(ir_carrier_pwm)

### Used to observe 6.0.0-6.2.0 bug
### https://github.com/adafruit/circuitpython/issues/4602
##ir_carrier_pwm_a2debug = pulseio.PWMOut(board.A2,
##                                        frequency=CARRIER_IRFREQ_SONY,
##                                        duty_cycle=round(20 / 100 * 65535))
##ir_pulseout_a2debug = pulseio.PulseOut(ir_carrier_pwm_a2debug)

### Sony timing values (in us) based on the ones in
### https://github.com/z3t0/Arduino-IRremote/blob/master/src/ir_Sony.cpp
### Disabling the addition of trail value is required to make this work
### trail=0 did not work
ir_encoder = adafruit_irremote.GenericTransmit(header=[2400, 600],
                                               one=   [1200, 600],
                                               zero=  [600,  600],
# CIRC17 - IR Replay
# (CircuitPython)
# this circuit was designed for use with the Metro Express Explorers Guide on Learn.Adafruit.com

# by Asher Lieber for Adafruit Industries

import time
import board
import pulseio
import digitalio
import array

# 38 for NEC
ir_led = pulseio.PWMOut(board.D3, frequency=1000 * 38, duty_cycle=0)
ir_led_send = pulseio.PulseOut(ir_led)

recv = pulseio.PulseIn(board.D2, maxlen=150, idle_state=True)

# creating DigitalInOut objects for a record and play button
but0 = digitalio.DigitalInOut(board.D9)  # record
but1 = digitalio.DigitalInOut(board.D8)  # playback

# setting up indicator LED
led = digitalio.DigitalInOut(board.D13)
led.switch_to_output()


# waits for IR to be detected, returns
def get_ir():
    ir_f = array.array('H')
    print('waiting for ir')
Пример #10
0
import array
import time

import pulseio

from pysirc import encoder


class Transmitter:
    """Generic transmitter for infrared remotes."""
    def __init__(self, pin, frequency=38_000, duty_cycle=2**15):
        self._pwm = pulseio.PWMOut(pin,
                                   frequency=frequency,
                                   duty_cycle=duty_cycle)
        self._pulseout = pulseio.PulseOut(self._pwm)

    def transmit_pulses(self, pulses):
        """Transmit a set of pre-calculated pulses."""

        if not isinstance(pulses, array.array):
            pulses = array.array("H", pulses)

        for _ in range(4):
            self._pulseout.send(pulses)
            time.sleep(0.025)


class SIRCTransmitter(Transmitter):
    """Transmitter for Sony SIRC remote protocol."""
    def __init__(self, pin, frequency=40_000, duty_cycle=2**15):
Пример #11
0
    Convert the HEX to Int [32, 223, 16, 239] and re-order them for use with the
    adafruit_irremote.GenericTransmit transmit function [223, 32, 239, 16]
    """
    n = 2
    out = [(string[i:i + n]) for i in range(0, len(string), n)]
    B1 = int(out[0], 16)
    B2 = int(out[1], 16)
    B3 = int(out[2], 16)
    B4 = int(out[3], 16)
    return [B2, B1, B4, B3]


# Create the relavent instances
PWM = pulseio.PWMOut(board.IR, frequency=38000, duty_cycle=2**15)
# Defines the IR signal pwm for communication with 50% duty cycle
Pulse_Out = pulseio.PulseOut(PWM)
# Creates the output pulse instance
Signal_Encoder = adafruit_irremote.GenericTransmit(header=[9500, 4500],
                                                   one=[550, 550],
                                                   zero=[550, 1700],
                                                   trail=0)
# Defines NEC signals to be sent

Dev_LG = {
    "PWR_ON": "20DF23DC",
    "PWR_OFF": "20DFA35C",
    "PWR_TOG": "20DF10EF",
    "HDMI1": "20DF738C",
}

Пример #12
0
 def on(self):
     # No IR Out without an extra capacitor on the power supply
     self.irtx = pulseio.PWMOut(board.IR_TX,
                                frequency=38000,
                                duty_cycle=2**15)
     self.irout = pulseio.PulseOut(self.irtx)