-
Notifications
You must be signed in to change notification settings - Fork 12
Mini Color TFT with Joystick FeatherWing #38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
6fa3141
06f1116
4982ad0
b0747f5
b3f356d
32fe548
5b78b06
dcbeccc
61bb721
829f6ab
7cd6391
e186a71
eed9b5c
2842b79
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
# The MIT License (MIT) | ||
# | ||
# Copyright (c) 2019 Melissa LeBlanc-Williams for Adafruit Industries LLC | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||
# of this software and associated documentation files (the "Software"), to deal | ||
# in the Software without restriction, including without limitation the rights | ||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
# copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included in | ||
# all copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
# THE SOFTWARE. | ||
""" | ||
`adafruit_featherwing.minitft_featherwing` | ||
==================================================== | ||
|
||
Helper for using the `Mini Color TFT with Joystick FeatherWing | ||
<https://www.adafruit.com/product/3321>`_. | ||
|
||
* Author(s): Melissa LeBlanc-Williams | ||
""" | ||
|
||
__version__ = "0.0.0-auto.0" | ||
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_FeatherWing.git" | ||
|
||
import board | ||
from micropython import const | ||
from adafruit_seesaw.seesaw import Seesaw | ||
import displayio | ||
from adafruit_st7735r import ST7735R | ||
|
||
BUTTON_RIGHT = const(7) | ||
BUTTON_DOWN = const(4) | ||
BUTTON_LEFT = const(3) | ||
BUTTON_UP = const(2) | ||
BUTTON_SEL = const(11) | ||
BUTTON_A = const(10) | ||
BUTTON_B = const(9) | ||
|
||
class MiniTFTFeatherWing: | ||
"""Class representing an `Mini Color TFT with Joystick FeatherWing | ||
<https://www.adafruit.com/product/3321>`_. | ||
|
||
Automatically uses the feather's I2C bus.""" | ||
def __init__(self, address=0x5E, i2c=None, spi=None): | ||
if i2c is None: | ||
i2c = board.I2C() | ||
if spi is None: | ||
spi = board.SPI() | ||
self._ss = Seesaw(i2c, address) | ||
self._button_mask = const((1 << BUTTON_RIGHT) | | ||
(1 << BUTTON_DOWN) | | ||
(1 << BUTTON_LEFT) | | ||
(1 << BUTTON_UP) | | ||
(1 << BUTTON_SEL) | | ||
(1 << BUTTON_A) | | ||
(1 << BUTTON_B)) | ||
self._ss.pin_mode_bulk(self._button_mask, self._ss.INPUT_PULLUP) | ||
displayio.release_displays() | ||
display_bus = displayio.FourWire(spi, command=board.D6, chip_select=board.D5) | ||
self._ss.pin_mode(8, self._ss.OUTPUT) | ||
self._ss.digital_write(8, True) # Reset the Display via Seesaw | ||
self._display = ST7735R(display_bus, width=160, height=80, colstart=24, | ||
rotation=270, bgr=True) | ||
|
||
@property | ||
def _buttons(self): | ||
return self._ss.digital_read_bulk(self._button_mask) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if there could be some caching here, so that if we want to check 5 different buttons, we don't make 5 separate calls to the seesaw. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if there was just a buttons = wing.buttons
if buttons.right:
...
elif buttons.left:
... |
||
|
||
@property | ||
def display(self): | ||
""" | ||
Returns the display object for doing fun displayio stuff on | ||
""" | ||
return self._display | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there any reason for this to be a property and not a straightforward attribute? |
||
|
||
@property | ||
def button_right(self): | ||
""" | ||
Checks and returns if right is currently being pressed | ||
""" | ||
return not self._buttons & (1 << BUTTON_RIGHT) | ||
|
||
@property | ||
def button_left(self): | ||
""" | ||
Checks and returns if left is currently being pressed | ||
""" | ||
return not self._buttons & (1 << BUTTON_LEFT) | ||
|
||
@property | ||
def button_up(self): | ||
""" | ||
Checks and returns if up is currently being pressed | ||
""" | ||
return not self._buttons & (1 << BUTTON_UP) | ||
|
||
@property | ||
def button_down(self): | ||
""" | ||
Checks and returns if down is currently being pressed | ||
""" | ||
return not self._buttons & (1 << BUTTON_DOWN) | ||
|
||
@property | ||
def button_a(self): | ||
""" | ||
Checks and returns if button A is currently being pressed | ||
""" | ||
return not self._buttons & (1 << BUTTON_A) | ||
|
||
@property | ||
def button_b(self): | ||
""" | ||
Checks and returns if button B is currently being pressed | ||
""" | ||
return not self._buttons & (1 << BUTTON_B) | ||
|
||
@property | ||
def button_select(self): | ||
""" | ||
Checks and returns if select is currently being pressed | ||
""" | ||
return not self._buttons & (1 << BUTTON_SEL) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
""" | ||
This example will display a CircuitPython console and | ||
print which button that is being pressed if any | ||
|
||
Note: This relies on displayio which is only widely | ||
available on CircuitPython 4.0 Beta 5 and later | ||
""" | ||
import time | ||
from adafruit_featherwing import minitft_featherwing | ||
|
||
minitft = minitft_featherwing.MiniTFTFeatherWing() | ||
|
||
while True: | ||
if minitft.button_right: | ||
print("Button RIGHT!") | ||
|
||
if minitft.button_down: | ||
print("Button DOWN!") | ||
|
||
if minitft.button_left: | ||
print("Button LEFT!") | ||
|
||
if minitft.button_up: | ||
print("Button UP!") | ||
|
||
if minitft.button_select: | ||
print("Button SELECT!") | ||
|
||
if minitft.button_a: | ||
print("Button A!") | ||
|
||
if minitft.button_b: | ||
print("Button B!") | ||
|
||
time.sleep(.01) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this
const()
does nothingThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this could be a class attribute, not an object attribute