Created
May 15, 2015 08:11
-
-
Save mdevaev/b447f2c8c67d957cc547 to your computer and use it in GitHub Desktop.
This file contains 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
from RPi import GPIO | |
import time | |
CLOCK_PIN = 4 | |
DATA_PIN = 15 | |
DELAY = 0.00020 | |
def send_bit(bit): | |
GPIO.output(CLOCK_PIN, 1) | |
GPIO.output(DATA_PIN, bit) | |
time.sleep(DELAY) | |
GPIO.output(CLOCK_PIN, 0) | |
time.sleep(DELAY) | |
GPIO.output(CLOCK_PIN, 1) | |
def send_byte(value): | |
value_bits = list(map(int, bin(value)[2:].zfill(8))) | |
value_bits.reverse() | |
message = [0] + value_bits + [int(not sum(value_bits) % 2), 1] | |
for bit in message: | |
send_bit(bit) | |
def send_bytes(codes): | |
for code in codes: | |
send_byte(code) | |
try: | |
GPIO.setmode(GPIO.BCM) | |
GPIO.setup(CLOCK_PIN, GPIO.OUT, initial=GPIO.HIGH) | |
GPIO.setup(DATA_PIN, GPIO.OUT, initial=GPIO.HIGH) | |
send_bytes([0x09]) # Press DEL | |
send_bytes([0xf0, 0x09]) # Release DEL | |
time.sleep(1) | |
send_bytes([0xe0, 0x5a]) # Press ENTER | |
send_bytes([0xe0, 0xf0, 0x5a]) # Release ENTER | |
finally: | |
GPIO.cleanup() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment