Skip to content

Commit 57b7e81

Browse files
authored
Merge pull request #26 from makermelissa/master
Added 7-Segment FeatherWing
2 parents 6e83321 + 2893945 commit 57b7e81

File tree

5 files changed

+225
-139
lines changed

5 files changed

+225
-139
lines changed

adafruit_featherwing/alphanum_featherwing.py

Lines changed: 5 additions & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -31,150 +31,16 @@
3131
__version__ = "0.0.0-auto.0"
3232
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_FeatherWing.git"
3333

34-
from time import sleep
3534
import adafruit_ht16k33.segments as segments
3635
from adafruit_featherwing import shared
36+
from adafruit_featherwing.led_segments import Segments
3737

38-
class AlphaNumFeatherWing:
38+
class AlphaNumFeatherWing(Segments):
3939
"""Class representing an `Adafruit 14-segment AlphaNumeric FeatherWing
4040
<https://www.adafruit.com/product/3139>`_.
4141
4242
Automatically uses the feather's I2C bus."""
4343
def __init__(self, address=0x70):
44-
self._seg14x4 = segments.Seg14x4(shared.I2C_BUS, address)
45-
self._seg14x4.auto_write = False
46-
47-
def print(self, value):
48-
"""
49-
Print a number or text to the display
50-
51-
:param value: The text or number to display
52-
:type value: str or int or float
53-
54-
.. code-block:: python
55-
56-
from adafruit_featherwing import alphanum_featherwing
57-
58-
display = alphanum_featherwing.AlphaNumFeatherWing()
59-
display.print(1234)
60-
61-
"""
62-
self._seg14x4.print(value)
63-
self._seg14x4.show()
64-
65-
def marquee(self, text, delay=0.25, loop=True):
66-
"""
67-
Automatically scroll the text at the specified delay between characters
68-
69-
:param str text: The text to display
70-
:param float delay: (optional) The delay in seconds to pause before scrolling
71-
to the next character (default=0.25)
72-
:param bool loop: (optional) Whether to endlessly loop the text (default=True)
73-
74-
.. code-block:: python
75-
76-
from adafruit_featherwing import alphanum_featherwing
77-
78-
display = alphanum_featherwing.AlphaNumFeatherWing()
79-
display.marquee('This is some really long text ')
80-
81-
"""
82-
if isinstance(text, str):
83-
self.fill(False)
84-
if loop:
85-
while True:
86-
self._scroll_marquee(text, delay)
87-
else:
88-
self._scroll_marquee(text, delay)
89-
90-
def _scroll_marquee(self, text, delay):
91-
for character in text:
92-
self._seg14x4.scroll()
93-
if character == '.':
94-
self._seg14x4[3] = ' '
95-
self._seg14x4[3] = character
96-
sleep(delay)
97-
self._seg14x4.show()
98-
99-
@property
100-
def blink_rate(self):
101-
"""
102-
Blink Rate returns the current rate that the text blinks.
103-
0 = Off
104-
1-3 = Successively slower blink rates
105-
106-
This example changes the blink rate and prints out the current setting
107-
108-
.. code-block:: python
109-
110-
from time import sleep
111-
from adafruit_featherwing import alphanum_featherwing
112-
113-
display = alphanum_featherwing.AlphaNumFeatherWing()
114-
display.print('Text')
115-
116-
for blink_rate in range(3, -1, -1):
117-
display.blink_rate = blink_rate
118-
print("Current Blink Rate is {}".format(display.blink_rate))
119-
sleep(4)
120-
121-
"""
122-
return self._seg14x4.blink_rate
123-
124-
@blink_rate.setter
125-
def blink_rate(self, rate):
126-
self._seg14x4.blink_rate = rate
127-
128-
@property
129-
def brightness(self):
130-
"""
131-
Brightness returns the current display brightness.
132-
0-15 = Dimmest to Brightest Setting
133-
134-
This example changes the brightness and prints out the current setting
135-
136-
.. code-block:: python
137-
138-
from time import sleep
139-
from adafruit_featherwing import alphanum_featherwing
140-
141-
display = alphanum_featherwing.AlphaNumFeatherWing()
142-
display.print('Text')
143-
144-
for brightness in range(0, 16):
145-
display.brightness = brightness
146-
print("Current Brightness is {}".format(display.brightness))
147-
sleep(0.2)
148-
149-
"""
150-
return self._seg14x4.brightness
151-
152-
@brightness.setter
153-
def brightness(self, brightness):
154-
self._seg14x4.brightness = brightness
155-
156-
def fill(self, fill):
157-
"""Change all Segments on or off
158-
:param bool fill: True turns all segments on, False turns all segments off
159-
160-
This example alternates between all filled and all empty segments.
161-
162-
.. code-block:: python
163-
164-
from time import sleep
165-
from adafruit_featherwing import alphanum_featherwing
166-
167-
display = alphanum_featherwing.AlphaNumFeatherWing()
168-
169-
while True:
170-
display.fill(True)
171-
sleep(0.5)
172-
display.fill(False)
173-
sleep(0.5)
174-
175-
"""
176-
if isinstance(fill, bool):
177-
self._seg14x4.fill(1 if fill else 0)
178-
self._seg14x4.show()
179-
else:
180-
raise ValueError('Must set to either True or False.')
44+
super().__init__()
45+
self._segments = segments.Seg14x4(shared.I2C_BUS, address)
46+
self._segments.auto_write = False

adafruit_featherwing/led_segments.py

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
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.led_segments`
24+
====================================================
25+
26+
Base Class for the AlphaNumeric FeatherWing and 7-Segment FeatherWing helpers_.
27+
28+
* Author(s): Melissa LeBlanc-Williams
29+
"""
30+
31+
__version__ = "0.0.0-auto.0"
32+
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_FeatherWing.git"
33+
34+
from time import sleep
35+
36+
#pylint: disable-msg=unsubscriptable-object, unsupported-assignment-operation
37+
38+
class Segments:
39+
"""Class representing an `Adafruit 14-segment AlphaNumeric FeatherWing
40+
<https://www.adafruit.com/product/3139>`_.
41+
42+
Automatically uses the feather's I2C bus."""
43+
def __init__(self):
44+
self._segments = None
45+
46+
def print(self, value):
47+
"""
48+
Print a number or text to the display
49+
50+
:param value: The text or number to display
51+
:type value: str or int or float
52+
53+
"""
54+
self._segments.print(value)
55+
self._segments.show()
56+
57+
def marquee(self, text, delay=0.25, loop=True):
58+
"""
59+
Automatically scroll the text at the specified delay between characters
60+
61+
:param str text: The text to display
62+
:param float delay: (optional) The delay in seconds to pause before scrolling
63+
to the next character (default=0.25)
64+
:param bool loop: (optional) Whether to endlessly loop the text (default=True)
65+
66+
"""
67+
if isinstance(text, str):
68+
self.fill(False)
69+
if loop:
70+
while True:
71+
self._scroll_marquee(text, delay)
72+
else:
73+
self._scroll_marquee(text, delay)
74+
75+
def _scroll_marquee(self, text, delay):
76+
"""
77+
Scroll through the text string once using the delay
78+
"""
79+
char_is_dot = False
80+
for character in text:
81+
self._segments.print(character)
82+
# Add delay if character is not a dot or more than 2 in a row
83+
if character != '.' or char_is_dot:
84+
sleep(delay)
85+
char_is_dot = (character == '.')
86+
self._segments.show()
87+
88+
def fill(self, fill):
89+
"""Change all Segments on or off
90+
91+
:param bool fill: True turns all segments on, False turns all segments off
92+
93+
"""
94+
if isinstance(fill, bool):
95+
self._segments.fill(1 if fill else 0)
96+
self._segments.show()
97+
else:
98+
raise ValueError('Must set to either True or False.')
99+
100+
@property
101+
def blink_rate(self):
102+
"""
103+
Blink Rate returns the current rate that the text blinks.
104+
0 = Off
105+
1-3 = Successively slower blink rates
106+
"""
107+
return self._segments.blink_rate
108+
109+
@blink_rate.setter
110+
def blink_rate(self, rate):
111+
self._segments.blink_rate = rate
112+
113+
@property
114+
def brightness(self):
115+
"""
116+
Brightness returns the current display brightness.
117+
0-15 = Dimmest to Brightest Setting
118+
"""
119+
return self._segments.brightness
120+
121+
@brightness.setter
122+
def brightness(self, brightness):
123+
self._segments.brightness = brightness
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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.sevensegment_featherwing`
24+
====================================================
25+
26+
Helper for using the `7-Segment LED HT16K33 FeatherWing <https://www.adafruit.com/product/3140>`_.
27+
28+
* Author(s): Melissa LeBlanc-Williams
29+
"""
30+
31+
__version__ = "0.0.0-auto.0"
32+
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_FeatherWing.git"
33+
34+
import adafruit_ht16k33.segments as segments
35+
from adafruit_featherwing import shared
36+
from adafruit_featherwing.led_segments import Segments
37+
38+
class SevenSegmentFeatherWing(Segments):
39+
"""Class representing an `Adafruit 7-Segment LED HT16K33 FeatherWing
40+
<https://www.adafruit.com/product/3140>`_.
41+
42+
Automatically uses the feather's I2C bus."""
43+
def __init__(self, address=0x70):
44+
super().__init__()
45+
self._segments = segments.Seg7x4(shared.I2C_BUS, address)
46+
self._segments.auto_write = False

docs/examples.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ Ensure your device works with this simple test.
2323
:caption: examples/featherwing_neopixel_simpletest.py
2424
:linenos:
2525

26+
.. literalinclude:: ../examples/featherwing_sevensegment_simpletest.py
27+
:caption: examples/featherwing_sevensegment_simpletest.py
28+
:linenos:
29+
2630
Other tests
2731
------------
2832

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
"""This example changes the fill, brightness, blink rates,
2+
shows number and text printing, displays a counter
3+
and then shows off the new marquee features."""
4+
5+
from time import sleep
6+
from adafruit_featherwing import sevensegment_featherwing
7+
8+
display = sevensegment_featherwing.SevenSegmentFeatherWing()
9+
10+
#Fill and empty all segments
11+
for count in range(0, 3):
12+
display.fill(True)
13+
sleep(0.5)
14+
display.fill(False)
15+
sleep(0.5)
16+
17+
#Display a number and text
18+
display.print(1234)
19+
sleep(1)
20+
display.print('FEED')
21+
22+
#Change brightness
23+
for brightness in range(0, 16):
24+
display.brightness = brightness
25+
sleep(0.1)
26+
27+
#Change blink rate
28+
for blink_rate in range(3, 0, -1):
29+
display.blink_rate = blink_rate
30+
sleep(4)
31+
display.blink_rate = 0
32+
33+
#Show a counter using decimals
34+
count = 975.0
35+
while count < 1025:
36+
count += 1
37+
display.print(count)
38+
sleep(0.1)
39+
40+
#Display a Time
41+
hour = 12
42+
for minute in range(15, 26):
43+
display.print("{}:{}".format(hour, minute))
44+
sleep(1)
45+
46+
#Show the Marquee
47+
display.marquee('Deadbeef 192.168.100.102... ', 0.2)

0 commit comments

Comments
 (0)