-
-
Save sebastianludwig/f8ae88dcdfecfd9477e6 to your computer and use it in GitHub Desktop.
TCL5947 from python - NOT working
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
#!/usr/bin/env python3 | |
import time | |
#import spidev | |
import RPi.GPIO as GPIO | |
GPIO.setmode(GPIO.BCM) | |
class GPIOOutput: | |
def __init__(self, pin): | |
self.pin = pin | |
GPIO.setup(pin, GPIO.OUT) | |
self.low() | |
print("just used %d as output" % pin) | |
def high(self): | |
GPIO.output(self.pin, GPIO.HIGH) | |
time.sleep(0.001) | |
def low(self): | |
GPIO.output(self.pin, GPIO.LOW) | |
time.sleep(0.001) | |
def __del__(self): | |
if GPIO: | |
GPIO.cleanup() | |
# spi = spidev.SpiDev() | |
# spi.open(0, 0) | |
#latch = GPIOOutput(17) | |
def bitbang(): | |
latch = GPIOOutput(17) | |
clock = GPIOOutput(11) | |
data = GPIOOutput(10) | |
while True: | |
try: | |
latch.low() | |
intensity = 1337 | |
for output in range(0,24): | |
for bit in range(11,-1, -1): | |
clock.low() | |
if intensity & (1 << bit): | |
data.high() | |
else: | |
data.low() | |
clock.high() | |
clock.low() | |
latch.high() | |
latch.low() | |
except (KeyboardInterrupt, SystemExit): | |
break | |
def loop(): | |
while True: | |
try: | |
latch.low() | |
intensity = 1337 | |
bytes = [] | |
for output in range(0,24): | |
lsb, msb = intensity & 0xFF, (intensity & 0xFF00) >> 8 | |
bytes.append(msb) | |
bytes.append(lsb) | |
spi.writebytes(bytes) | |
latch.high() | |
time.sleep(0.1) | |
latch.low() | |
time.sleep(0.3) | |
except (KeyboardInterrupt, SystemExit): | |
spi.close() | |
break | |
if __name__ == '__main__': | |
# loop() | |
bitbang() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment