Skip to content

Instantly share code, notes, and snippets.

@ak1211
Last active June 16, 2020 04:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ak1211/28bec35b5e8cd202e9c4be85b63d42b4 to your computer and use it in GitHub Desktop.
Save ak1211/28bec35b5e8cd202e9c4be85b63d42b4 to your computer and use it in GitHub Desktop.
赤外線リモコン信号取得と送信用 circuit python プログラム
# https://ak1211.com/7586 (main.py)
# Copyright 2020 Akihiro Yamamoto
# Licensed under the Apache License, Version 2.0
from digitalio import DigitalInOut, Direction
import array
import board
import pulseio
import supervisor
import sys
import time
# IRM
irm_pulse = pulseio.PulseIn(board.D0, maxlen=2000, idle_state=True)
# PWM
# carrier: 38kHz
# duty cycle: 1/3 = 65536/3 = 21845
pwm = pulseio.PWMOut(board.D1, duty_cycle=21845, frequency=38000, variable_frequency=False)
infrared_led_pulse = pulseio.PulseOut(pwm)
led = DigitalInOut(board.D13)
led.direction = Direction.OUTPUT
toggle = True
while True:
if (len(irm_pulse) > 10):
irm_pulse.pause()
output = '{"name":['
for i in range(len(irm_pulse)):
output = output + "{},".format(irm_pulse[i])
output = output[:-1] + "]}"
print(output)
irm_pulse.resume()
irm_pulse.clear()
# LEDを点滅させる
led.value = toggle
toggle = not toggle
serial_inputs = ""
# 時間待ちのついでにシリアル入力をしておく
for c in range(6):
time.sleep(0.2)
while supervisor.runtime.serial_bytes_available:
serial_inputs += sys.stdin.read(1)
# 入力文字列を配列にする
start = serial_inputs.find('[')
end = serial_inputs.rfind(']')
if (end-start) > 10:
contents = serial_inputs[1+start:end]
to_output_pulses = array.array( 'H', [int(v.strip()) for v in contents.split(',')] )
# 赤外線リモコン信号送出
infrared_led_pulse.send(to_output_pulses)
@ak1211
Copy link
Author

ak1211 commented Jun 16, 2020

update

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment