Skip to content

Instantly share code, notes, and snippets.

@RoyWiggins
Last active February 29, 2016 07:13
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 RoyWiggins/60ed013071c7c0cdf442 to your computer and use it in GitHub Desktop.
Save RoyWiggins/60ed013071c7c0cdf442 to your computer and use it in GitHub Desktop.
import pykka
from mopidy import core
import Adafruit_CharLCD as LCD
import time,random, threading
class TestFrontend(pykka.ThreadingActor, core.CoreListener):
def __init__(self, config, core):
super(TestFrontend, self).__init__()
self.core = core
self.lcd = LCD.Adafruit_CharLCDPlate()
self.lcd.set_color(1.0, 1.0, 1.0)
self.lcd.clear()
self.msg("$" * 16)
self.lcd.clear()
self.msg("!" * 16)
def msg(self,text):
c = time.clock()
for char in text:
self.write8(ord(char), True)
print "---",time.clock() - c
def write8(self, value, char_mode=False):
"""Write 8-bit value in character or data mode. Value should be an int
value from 0-255, and char_mode is True if character data or False if
non-character data (default).
"""
c = time.clock()
# One millisecond delay to prevent writing too quickly.
self.lcd._delay_microseconds(1000)
# Set character / data bit.
self.lcd._gpio.output(self.lcd._rs, char_mode)
# Write upper 4 bits.
self.lcd._gpio.output_pins({ self.lcd._d4: ((value >> 4) & 1) > 0,
self.lcd._d5: ((value >> 5) & 1) > 0,
self.lcd._d6: ((value >> 6) & 1) > 0,
self.lcd._d7: ((value >> 7) & 1) > 0 })
self.lcd._pulse_enable()
# Write lower 4 bits.
self.lcd._gpio.output_pins({ self.lcd._d4: (value & 1) > 0,
self.lcd._d5: ((value >> 1) & 1) > 0,
self.lcd._d6: ((value >> 2) & 1) > 0,
self.lcd._d7: ((value >> 3) & 1) > 0 })
self.lcd._pulse_enable()
print time.clock() - c
def on_start(self):
pass
if __name__ == "__main__":
test = TestFrontend(None,None)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment