Skip to content

Instantly share code, notes, and snippets.

@rsbohn
Created January 17, 2022 20:01
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 rsbohn/7af63a1efe84a1283fc6259eefe025a5 to your computer and use it in GitHub Desktop.
Save rsbohn/7af63a1efe84a1283fc6259eefe025a5 to your computer and use it in GitHub Desktop.
Visible state of digital input pins.
# SPDX-FileCopyrightText: Copyright (c) 2022 Randall Bohn (dexter)
#
# SPDX-License-Identifier: MIT
# A little fun in the Funhouse
import time
import board
import digitalio
import displayio
import vectorio
from adafruit_displayio_layout.layouts.grid_layout import GridLayout
from adafruit_displayio_layout.widgets.widget import Widget
purple=0x660099
blue=0x0000cc
white=0xcccccc
gray=0x666666
class Pin(Widget):
"Display the state of the chosen (digital input) pin."
def __init__(self, pin, color=0xFFFF99, **kwargs):
super().__init__(**kwargs)
self.pin = digitalio.DigitalInOut(pin)
self.palette = displayio.Palette(1)
self.palette[0] = color
self.vc = vectorio.Circle(radius=18, x=20, y=20, pixel_shader=self.palette)
self.append(self.vc)
def resize(self, wtick, htick):
self._width = wtick
self._height = htick
self.vc.x = wtick//2
self.vc.y = int(htick*3//4)
def update(self):
if self.pin.value:
place = self._height * 1//4
else:
place = self._height * 3//4
self.vc.y = place
display = board.DISPLAY
splash = displayio.Group()
display.show(splash)
layout = GridLayout(0,0,display.width,display.height//2,
grid_size=(3,1), divider_lines=True)
splash.append(layout)
layout.add_content(Pin(board.BUTTON_UP, purple), (0,0), (1,1))
layout.add_content(Pin(board.BUTTON_SELECT, blue), (1,0), (1,1))
layout.add_content(Pin(board.BUTTON_DOWN, white), (2,0), (1,1))
while True:
for x in range(3):
layout.get_cell((x,0)).update()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment