# Setup SPI bus using hardware SPI: spi = board.SPI() # Create the ST7789 display: adjust x / y offsets depending on rotation and your screen (often by 80) display = st7789.ST7789(spi, cs=cs_pin, dc=dc_pin, rst=reset_pin, x_offset=0, y_offset=0, rotation=0, baudrate=BAUDRATE) # Main loop: while True: # Fill the screen red, green, blue, then black: for color in ((255, 0, 0), (0, 255, 0), (0, 0, 255)): display.fill(color565(color)) # Clear the display display.fill(0) # Draw a red pixel in the center. display.pixel(display.width // 2, display.height // 2, color565(255, 0, 0)) # Pause 2 seconds. time.sleep(2) # Clear the screen a random color display.fill( color565(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))) # Pause 2 seconds. time.sleep(2)
display = st7789.ST7789(board.SPI(), cs=cs_pin, dc=dc_pin, rst=reset_pin, baudrate=BAUDRATE, width=135, height=240, x_offset=53, y_offset=40) backlight = digitalio.DigitalInOut(board.D22) backlight.switch_to_output() backlight.value = True buttonA = digitalio.DigitalInOut(board.D23) buttonB = digitalio.DigitalInOut(board.D24) buttonA.switch_to_input() buttonB.switch_to_input() # Main loop: while True: if buttonA.value and buttonB.value: backlight.value = False # turn off backlight else: backlight.value = True # turn on backlight if buttonB.value and not buttonA.value: # just button A pressed display.fill(color565(255, 0, 0)) # red if buttonA.value and not buttonB.value: # just button B pressed display.fill(color565(0, 0, 255)) # blue if not buttonA.value and not buttonB.value: # none pressed display.fill(color565(0, 255, 0)) # green
# these setup the code for our buttons and the backlight and tell the pi to treat the GPIO pins as digitalIO vs analogIO backlight = digitalio.DigitalInOut(board.D22) backlight.switch_to_output() backlight.value = True buttonA = digitalio.DigitalInOut(board.D23) buttonB = digitalio.DigitalInOut(board.D24) buttonA.switch_to_input() buttonB.switch_to_input() # get a color from the user screenColor = None while not screenColor: try: # get a color from the user and convert it to RGB screenColor = color565(*list(webcolors.name_to_rgb(input('Type the name of a color and hit enter: ')))) except ValueError: # catch colors we don't recognize and go again print("whoops I don't know that one") # Main loop: while True: if buttonA.value and buttonB.value: backlight.value = False # turn off backlight else: backlight.value = True # turn on backlight if buttonB.value and not buttonA.value: # just button A pressed display.fill(screenColor) # set the screen to the users color if buttonA.value and not buttonB.value: # just button B pressed display.fill(color565(255, 255, 255)) # set the screen to white if not buttonA.value and not buttonB.value: # none pressed display.fill(color565(0, 255, 0)) # green
CPU = subprocess.check_output(cmd, shell=True).decode("utf-8") cmd = "free -m | awk 'NR==2{printf \"Mem: %s/%s MB %.2f%%\", $3,$2,$3*100/$2 }'" MemUsage = subprocess.check_output(cmd, shell=True).decode("utf-8") cmd = "df -h | awk '$NF==\"/\"{printf \"Disk: %d/%d GB %s\", $3,$2,$5}'" Disk = subprocess.check_output(cmd, shell=True).decode("utf-8") cmd = "cat /sys/class/thermal/thermal_zone0/temp | awk \'{printf \"CPU Temp: %.1f C\", $(NF-0) / 1000}\'" # pylint: disable=line-too-long Temp = subprocess.check_output(cmd, shell=True).decode("utf-8") # Write four lines of text. y = top draw.text((x, y), IP, font=font, fill="#FFFFFF") y += font.getsize(IP)[1] draw.text((x, y), CPU, font=font, fill="#FFFF00") y += font.getsize(CPU)[1] draw.text((x, y), MemUsage, font=font, fill="#00FF00") y += font.getsize(MemUsage)[1] draw.text((x, y), Disk, font=font, fill="#6060FF") y += font.getsize(Disk)[1] draw.text((x, y), Temp, font=font, fill="#FF60FF") y += font.getsize(Temp)[1] # strDiff = "" + diff # draw.text( (x, y), strDiff, font=font, fill="#FFFFFF" ) # iDiffX = diff * 200 iDiffX = 200 draw.fill(color565(250, 100, 100)) # Display image. disp.image(image, rotation) time.sleep(0.2)
# ---------------------------------------------------------------------- # Test leds (-O flag) # ---------------------------------------------------------------------- if rpi.OutputDisplay: if first: print('Test OutputDisplay') print('a, b, repeat', rpi.buttonA.value, rpi.buttonB.value, repeat) if rpi.buttonA.value and rpi.buttonB.value: rpi.backlight.value = False # turn off backlight repeat -= 1 if repeat == 0: print('break, repeat = 0') # Stop no powerdown else: rpi.backlight.value = True # turn on backlight if rpi.buttonB.value and not rpi.buttonA.value: # just button A pressed rpi.st7789.fill(color565(255, 0, 0)) # red if rpi.buttonA.value and not rpi.buttonB.value: # just button B pressed rpi.st7789.fill(color565(0, 0, 255)) # blue if not rpi.buttonA.value and not rpi.buttonB.value: # none pressed rpi.st7789.fill(color565(0, 255, 0)) # green # ---------------------------------------------------------------------- # Stop for next button press # ---------------------------------------------------------------------- first = False time.sleep(.25) ShutdownIfRequested()
def __enter__(self): self.display.fill(color565(0, 0, 0)) self.display.init() self.display.rotation = 180 self.backlight_pin.value = True return self
cs_pin = digitalio.DigitalInOut(board.CE0) dc_pin = digitalio.DigitalInOut(board.D25) reset_pin = None BAUDRATE = 64000000 # The pi can be very fast! # Create the ST7789 display: display = st7789.ST7789(board.SPI(), cs=cs_pin, dc=dc_pin, rst=reset_pin, baudrate=BAUDRATE, rotation=90, width=240, height=240, y_offset=80) display.fill(color565(100, 0, 0)) backlight = digitalio.DigitalInOut(board.D22) backlight.switch_to_output() backlight.value = True buttonA = digitalio.DigitalInOut(board.D23) buttonB = digitalio.DigitalInOut(board.D24) buttonA.switch_to_input() buttonB.switch_to_input() if display.rotation % 180 == 90: width = display.height height = display.width else: width = display.width height = display.height
with open(r'/etc/pizerotimer.yml') as file: config = yaml.load(file, Loader=yaml.FullLoader) # date/times in database will be UTC - need this for determining "local" # start of week. local_tz = pytz.timezone(config['options']['local_tz']) # Database Setup conn = sqlite3.connect(config['options']['database']) db = conn.cursor() database_setup() # Setup screen (r, g, b) = config['colors']['background_under_threshold'].split(',') background_under_threshold = color565(int(r), int(g), int(b)) (r, g, b) = config['colors']['background_over_threshold'].split(',') background_over_threshold = color565(int(r), int(g), int(b)) (r, g, b) = config['colors']['status_bar_color'].split(',') status_bar_color = color565(int(r), int(g), int(b)) (r, g, b) = config['colors']['status_bar_outline_color'].split(',') status_bar_outline_color = color565(int(r), int(g), int(b)) (r, g, b) = config['colors']['foreground_color'].split(',') foreground_color = color565(int(r), int(g), int(b)) (r, g, b) = config['colors']['active_day_color'].split(',') active_day_color = color565(int(r), int(g), int(b)) (r, g, b) = config['colors']['inactive_day_color'].split(',') inactive_day_color = color565(int(r), int(g), int(b)) test_color = color565(0, 0, 0) background_color = background_under_threshold turn_on_backlight()