def init_hw(): # Display i2c = busio.I2C(board.SCL, board.SDA) display = Sparkfun_SerLCD_I2C(i2c) display.clear() # Thermocouples spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO) therm0 = MAX31855(spi, digitalio.DigitalInOut(pinsetup['therm0'])) therm1 = MAX31855(spi, digitalio.DigitalInOut(pinsetup['therm1'])) # Relays (high to enable because we go through the transistor switch) relay0 = digitalio.DigitalInOut(pinsetup['relay0']) relay0.direction = digitalio.Direction.OUTPUT relay0.value = False relay1 = digitalio.DigitalInOut(pinsetup['relay1']) relay1.direction = digitalio.Direction.OUTPUT relay1.value = False # Encoder setup enc = rotaryio.IncrementalEncoder(pinsetup['encoderA'], pinsetup['encoderB']) pb = digitalio.DigitalInOut(pinsetup['button']) pb.direction = digitalio.Direction.INPUT pb.pull = digitalio.Pull.DOWN switch = Debouncer(pb) # RGB on dial (low to enable) r = digitalio.DigitalInOut(pinsetup['r']) r.direction = digitalio.Direction.OUTPUT r.value = True g = digitalio.DigitalInOut(pinsetup['g']) g.direction = digitalio.Direction.OUTPUT g.value = True b = digitalio.DigitalInOut(pinsetup['b']) b.direction = digitalio.Direction.OUTPUT b.value = True return (display, therm0, therm1, relay0, relay1, enc, switch, (r, g, b))
def __init__(self, logger): self.logger = logger i2c = busio.I2C(1, 0) self.serlcd = Sparkfun_SerLCD_I2C(i2c) self.colors = { "Black": [0, 0, 0], "White": [255, 255, 255], "Red": [255, 0, 0], "Orange": [255, 140, 0], "Yellow": [255, 255, 0], "Green": [0, 255, 0], "Teal": [0, 255, 255], "Blue": [0, 0, 255], "Indigo": [75, 0, 140], "Purple": [130, 32, 240], "Grey": [128, 128, 128] } self.countDownDigits = 0 self.lcdRow = 2 self.lcdCol = 16 self.setColorName("White") self.writeCenter("Shots Alarm", " ") self.shots = False
Based on Arduino code written by Gaston Williams and Nathan Seidle @ Sparkfun, August 22, 2018. Example 10 - Turn Off Display: This program writes a message to the display, then uses the display(True) and display(False) methods to turn the display on and off. """ from time import sleep import board import busio from sparkfun_serlcd import Sparkfun_SerLCD_I2C i2c = busio.I2C(board.SCL, board.SDA) serlcd = Sparkfun_SerLCD_I2C(i2c) print('Example 10: Turn Off Display') print('Press Ctrl-C to end program.') serlcd.clear() serlcd.write("Display on/off.") try: while True: serlcd.display(False) sleep(0.5) serlcd.display(True) sleep(0.5)