adafruit / Adafruit_CircuitPython_FeatherWing

CircuitPython classes for Adafruit FeatherWings
MIT License
11 stars 13 forks source link

Mini Color TFT with Joystick FeatherWing #38

Closed makermelissa closed 5 years ago

makermelissa commented 5 years ago

Here's my take on a Mini TFT with Joystick FeatherWing Library. This one is complete with simpletest and documentation changes.

hexthat commented 5 years ago

with this how do you adjust the brightness?

makermelissa commented 5 years ago

Good point @hexthat. I’ll add that.

makermelissa commented 5 years ago

Thanks @deshipu for reviewing this. I’ll make some changes tonight.

deshipu commented 5 years ago

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.

makermelissa commented 5 years ago

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.

makermelissa commented 5 years ago

Ok, requested changes implemented.

deshipu commented 5 years ago

Thank you, it looks great!