Skip to content

Commit d6b29fd

Browse files
author
Melissa LeBlanc-Williams
committed
Added 7-Segment FeatherWing
1 parent f16b992 commit d6b29fd

File tree

4 files changed

+222
-139
lines changed

4 files changed

+222
-139
lines changed

adafruit_featherwing/alphanum_featherwing.py

Lines changed: 4 additions & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -31,150 +31,15 @@
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+
self._segments = segments.Seg14x4(shared.I2C_BUS, address)
45+
self._segments.auto_write = False

adafruit_featherwing/led_segments.py

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