Closed makermelissa closed 5 years ago
with this how do you adjust the brightness?
Good point @hexthat. I’ll add that.
Thanks @deshipu for reviewing this. I’ll make some changes tonight.
I'm playing with PyBadge now, and I came up with this code for the buttons for it:
import board
import digitalio
import bitbangio
import time
import collections
Buttons = collections.namedtuple('Buttons',
'left up down right select start a b')
class PyBadgeButtons:
def __init__(self):
self._bus = bitbangio.SPI(clock=board.BUTTON_CLOCK,
MISO=board.BUTTON_OUT)
while not self._bus.try_lock():
pass
self._bus.configure(polarity=1, phase=1)
self._latch = digitalio.DigitalInOut(board.BUTTON_LATCH)
self._latch.switch_to_output(value=0)
self._buffer = bytearray(1)
@property
def pressed(self):
self._latch.value = 1
self._bus.readinto(self._buffer)
self._latch.value = 0
pressed = self._buffer[0]
return Buttons(*[bool(pressed & (1 << button)) for button in range(8)])
buttons = PyBadgeButtons()
while True:
print(buttons.pressed)
time.sleep(1)
I think we could use something very similar here.
Ok, backlight added, unnecessary const() removed, display is an attribute, and buttons returned as named tuple so they are only read once per loop instead of 7 times.
Ok, requested changes implemented.
Thank you, it looks great!
Here's my take on a Mini TFT with Joystick FeatherWing Library. This one is complete with simpletest and documentation changes.