Skip to content

Commit d047cf8

Browse files
authored
Merge pull request #38 from makermelissa/master
Mini Color TFT with Joystick FeatherWing
2 parents 5ea0eb4 + 2842b79 commit d047cf8

File tree

6 files changed

+148
-1
lines changed

6 files changed

+148
-1
lines changed

README.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ These drivers depends on:
2828
* `DotStar <https://github.com/adafruit/Adafruit_CircuitPython_DotStar>`_
2929
* `NeoPixel <https://github.com/adafruit/Adafruit_CircuitPython_NeoPixel>`_
3030
* `DS3231 <https://github.com/adafruit/Adafruit_CircuitPython_DS3231>`_
31+
* `ST7735R <https://github.com/adafruit/Adafruit_CircuitPython_ST7735R>`_
3132

3233
Please ensure all dependencies are available on the CircuitPython filesystem.
3334
This is easily achieved by downloading
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
# The MIT License (MIT)
2+
#
3+
# Copyright (c) 2019 Melissa LeBlanc-Williams for Adafruit Industries LLC
4+
#
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy
6+
# of this software and associated documentation files (the "Software"), to deal
7+
# in the Software without restriction, including without limitation the rights
8+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
# copies of the Software, and to permit persons to whom the Software is
10+
# furnished to do so, subject to the following conditions:
11+
#
12+
# The above copyright notice and this permission notice shall be included in
13+
# all copies or substantial portions of the Software.
14+
#
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
# THE SOFTWARE.
22+
"""
23+
`adafruit_featherwing.minitft_featherwing`
24+
====================================================
25+
26+
Helper for using the `Mini Color TFT with Joystick FeatherWing
27+
<https://www.adafruit.com/product/3321>`_.
28+
29+
* Author(s): Melissa LeBlanc-Williams
30+
"""
31+
32+
__version__ = "0.0.0-auto.0"
33+
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_FeatherWing.git"
34+
35+
from collections import namedtuple
36+
import board
37+
from micropython import const
38+
from adafruit_seesaw.seesaw import Seesaw
39+
from adafruit_seesaw.pwmout import PWMOut
40+
import displayio
41+
from adafruit_st7735r import ST7735R
42+
43+
BUTTON_RIGHT = const(7)
44+
BUTTON_DOWN = const(4)
45+
BUTTON_LEFT = const(3)
46+
BUTTON_UP = const(2)
47+
BUTTON_SEL = const(11)
48+
BUTTON_A = const(10)
49+
BUTTON_B = const(9)
50+
51+
Buttons = namedtuple("Buttons", "up down left right a b select")
52+
53+
class MiniTFTFeatherWing:
54+
"""Class representing an `Mini Color TFT with Joystick FeatherWing
55+
<https://www.adafruit.com/product/3321>`_.
56+
57+
Automatically uses the feather's I2C bus."""
58+
59+
_button_mask = ((1 << BUTTON_RIGHT) |
60+
(1 << BUTTON_DOWN) |
61+
(1 << BUTTON_LEFT) |
62+
(1 << BUTTON_UP) |
63+
(1 << BUTTON_SEL) |
64+
(1 << BUTTON_A) |
65+
(1 << BUTTON_B))
66+
67+
def __init__(self, address=0x5E, i2c=None, spi=None):
68+
if i2c is None:
69+
i2c = board.I2C()
70+
if spi is None:
71+
spi = board.SPI()
72+
self._ss = Seesaw(i2c, address)
73+
self._backlight = PWMOut(self._ss, 5)
74+
self._backlight.duty_cycle = 0
75+
self._ss.pin_mode_bulk(self._button_mask, self._ss.INPUT_PULLUP)
76+
displayio.release_displays()
77+
display_bus = displayio.FourWire(spi, command=board.D6, chip_select=board.D5)
78+
self._ss.pin_mode(8, self._ss.OUTPUT)
79+
self._ss.digital_write(8, True) # Reset the Display via Seesaw
80+
self.display = ST7735R(display_bus, width=160, height=80, colstart=24,
81+
rotation=270, bgr=True)
82+
83+
@property
84+
def backlight(self):
85+
"""
86+
Return the current backlight duty cycle value
87+
"""
88+
return self._backlight.duty_cycle / 255
89+
90+
@backlight.setter
91+
def backlight(self, brightness):
92+
"""
93+
Set the backlight duty cycle
94+
"""
95+
self._backlight.duty_cycle = int(255 * min(max(1 - brightness, 0.0), 1.0))
96+
97+
@property
98+
def buttons(self):
99+
"""
100+
Return a set of buttons with current push values
101+
"""
102+
button_values = self._ss.digital_read_bulk(self._button_mask)
103+
return Buttons(*[not button_values & (1 << button) for button in
104+
(BUTTON_UP, BUTTON_DOWN, BUTTON_LEFT, BUTTON_RIGHT,
105+
BUTTON_A, BUTTON_B, BUTTON_SEL)])

docs/api.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,6 @@
2424

2525
.. automodule:: adafruit_featherwing.matrix_featherwing
2626
:members:
27+
28+
.. automodule:: adafruit_featherwing.minitft_featherwing
29+
:members:

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
# Uncomment the below if you use native CircuitPython modules such as
1919
# digitalio, micropython and busio. List the modules you use. Without it, the
2020
# autodoc module docs will fail to generate with a warning.
21-
autodoc_mock_imports = ["board", "busio"]
21+
autodoc_mock_imports = ["board", "busio", "displayio", "adafruit_st7735r"]
2222

2323
intersphinx_mapping = {
2424
'python': ('https://docs.python.org/3.4', None),

docs/examples.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ Ensure your device works with this simple test.
3939
:caption: examples/featherwing_matrix_simpletest.py
4040
:linenos:
4141

42+
.. literalinclude:: ../examples/featherwing_minitft_simpletest.py
43+
:caption: examples/featherwing_minitft_simpletest.py
44+
:linenos:
45+
4246
Other Examples
4347
---------------
4448

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
"""
2+
This example display a CircuitPython console and
3+
print which button that is being pressed if any
4+
"""
5+
import time
6+
from adafruit_featherwing import minitft_featherwing
7+
8+
minitft = minitft_featherwing.MiniTFTFeatherWing()
9+
10+
while True:
11+
buttons = minitft.buttons
12+
13+
if buttons.right:
14+
print("Button RIGHT!")
15+
16+
if buttons.down:
17+
print("Button DOWN!")
18+
19+
if buttons.left:
20+
print("Button LEFT!")
21+
22+
if buttons.up:
23+
print("Button UP!")
24+
25+
if buttons.select:
26+
print("Button SELECT!")
27+
28+
if buttons.a:
29+
print("Button A!")
30+
31+
if buttons.b:
32+
print("Button B!")
33+
34+
time.sleep(.001)

0 commit comments

Comments
 (0)