Skip to content

Added 7-Segment FeatherWing #26

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

Merged
merged 5 commits into from
Feb 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
144 changes: 5 additions & 139 deletions adafruit_featherwing/alphanum_featherwing.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,150 +31,16 @@
__version__ = "0.0.0-auto.0"
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_FeatherWing.git"

from time import sleep
import adafruit_ht16k33.segments as segments
from adafruit_featherwing import shared
from adafruit_featherwing.led_segments import Segments

class AlphaNumFeatherWing:
class AlphaNumFeatherWing(Segments):
"""Class representing an `Adafruit 14-segment AlphaNumeric FeatherWing
<https://www.adafruit.com/product/3139>`_.

Automatically uses the feather's I2C bus."""
def __init__(self, address=0x70):
self._seg14x4 = segments.Seg14x4(shared.I2C_BUS, address)
self._seg14x4.auto_write = False

def print(self, value):
"""
Print a number or text to the display

:param value: The text or number to display
:type value: str or int or float

.. code-block:: python

from adafruit_featherwing import alphanum_featherwing

display = alphanum_featherwing.AlphaNumFeatherWing()
display.print(1234)

"""
self._seg14x4.print(value)
self._seg14x4.show()

def marquee(self, text, delay=0.25, loop=True):
"""
Automatically scroll the text at the specified delay between characters

:param str text: The text to display
:param float delay: (optional) The delay in seconds to pause before scrolling
to the next character (default=0.25)
:param bool loop: (optional) Whether to endlessly loop the text (default=True)

.. code-block:: python

from adafruit_featherwing import alphanum_featherwing

display = alphanum_featherwing.AlphaNumFeatherWing()
display.marquee('This is some really long text ')

"""
if isinstance(text, str):
self.fill(False)
if loop:
while True:
self._scroll_marquee(text, delay)
else:
self._scroll_marquee(text, delay)

def _scroll_marquee(self, text, delay):
for character in text:
self._seg14x4.scroll()
if character == '.':
self._seg14x4[3] = ' '
self._seg14x4[3] = character
sleep(delay)
self._seg14x4.show()

@property
def blink_rate(self):
"""
Blink Rate returns the current rate that the text blinks.
0 = Off
1-3 = Successively slower blink rates

This example changes the blink rate and prints out the current setting

.. code-block:: python

from time import sleep
from adafruit_featherwing import alphanum_featherwing

display = alphanum_featherwing.AlphaNumFeatherWing()
display.print('Text')

for blink_rate in range(3, -1, -1):
display.blink_rate = blink_rate
print("Current Blink Rate is {}".format(display.blink_rate))
sleep(4)

"""
return self._seg14x4.blink_rate

@blink_rate.setter
def blink_rate(self, rate):
self._seg14x4.blink_rate = rate

@property
def brightness(self):
"""
Brightness returns the current display brightness.
0-15 = Dimmest to Brightest Setting

This example changes the brightness and prints out the current setting

.. code-block:: python

from time import sleep
from adafruit_featherwing import alphanum_featherwing

display = alphanum_featherwing.AlphaNumFeatherWing()
display.print('Text')

for brightness in range(0, 16):
display.brightness = brightness
print("Current Brightness is {}".format(display.brightness))
sleep(0.2)

"""
return self._seg14x4.brightness

@brightness.setter
def brightness(self, brightness):
self._seg14x4.brightness = brightness

def fill(self, fill):
"""Change all Segments on or off
:param bool fill: True turns all segments on, False turns all segments off

This example alternates between all filled and all empty segments.

.. code-block:: python

from time import sleep
from adafruit_featherwing import alphanum_featherwing

display = alphanum_featherwing.AlphaNumFeatherWing()

while True:
display.fill(True)
sleep(0.5)
display.fill(False)
sleep(0.5)

"""
if isinstance(fill, bool):
self._seg14x4.fill(1 if fill else 0)
self._seg14x4.show()
else:
raise ValueError('Must set to either True or False.')
super().__init__()
self._segments = segments.Seg14x4(shared.I2C_BUS, address)
self._segments.auto_write = False
123 changes: 123 additions & 0 deletions adafruit_featherwing/led_segments.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
# 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.led_segments`
====================================================

Base Class for the AlphaNumeric FeatherWing and 7-Segment FeatherWing helpers_.

* Author(s): Melissa LeBlanc-Williams
"""

__version__ = "0.0.0-auto.0"
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_FeatherWing.git"

from time import sleep

#pylint: disable-msg=unsubscriptable-object, unsupported-assignment-operation

class Segments:
"""Class representing an `Adafruit 14-segment AlphaNumeric FeatherWing
<https://www.adafruit.com/product/3139>`_.

Automatically uses the feather's I2C bus."""
def __init__(self):
self._segments = None

def print(self, value):
"""
Print a number or text to the display

:param value: The text or number to display
:type value: str or int or float

"""
self._segments.print(value)
self._segments.show()

def marquee(self, text, delay=0.25, loop=True):
"""
Automatically scroll the text at the specified delay between characters

:param str text: The text to display
:param float delay: (optional) The delay in seconds to pause before scrolling
to the next character (default=0.25)
:param bool loop: (optional) Whether to endlessly loop the text (default=True)

"""
if isinstance(text, str):
self.fill(False)
if loop:
while True:
self._scroll_marquee(text, delay)
else:
self._scroll_marquee(text, delay)

def _scroll_marquee(self, text, delay):
"""
Scroll through the text string once using the delay
"""
char_is_dot = False
for character in text:
self._segments.print(character)
# Add delay if character is not a dot or more than 2 in a row
if character != '.' or char_is_dot:
sleep(delay)
char_is_dot = (character == '.')
self._segments.show()

def fill(self, fill):
"""Change all Segments on or off

:param bool fill: True turns all segments on, False turns all segments off

"""
if isinstance(fill, bool):
self._segments.fill(1 if fill else 0)
self._segments.show()
else:
raise ValueError('Must set to either True or False.')

@property
def blink_rate(self):
"""
Blink Rate returns the current rate that the text blinks.
0 = Off
1-3 = Successively slower blink rates
"""
return self._segments.blink_rate

@blink_rate.setter
def blink_rate(self, rate):
self._segments.blink_rate = rate

@property
def brightness(self):
"""
Brightness returns the current display brightness.
0-15 = Dimmest to Brightest Setting
"""
return self._segments.brightness

@brightness.setter
def brightness(self, brightness):
self._segments.brightness = brightness
46 changes: 46 additions & 0 deletions adafruit_featherwing/sevensegment_featherwing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# 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.sevensegment_featherwing`
====================================================

Helper for using the `7-Segment LED HT16K33 FeatherWing <https://www.adafruit.com/product/3140>`_.

* Author(s): Melissa LeBlanc-Williams
"""

__version__ = "0.0.0-auto.0"
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_FeatherWing.git"

import adafruit_ht16k33.segments as segments
from adafruit_featherwing import shared
from adafruit_featherwing.led_segments import Segments

class SevenSegmentFeatherWing(Segments):
"""Class representing an `Adafruit 7-Segment LED HT16K33 FeatherWing
<https://www.adafruit.com/product/3140>`_.

Automatically uses the feather's I2C bus."""
def __init__(self, address=0x70):
super().__init__()
self._segments = segments.Seg7x4(shared.I2C_BUS, address)
self._segments.auto_write = False
4 changes: 4 additions & 0 deletions docs/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ Ensure your device works with this simple test.
:caption: examples/featherwing_neopixel_simpletest.py
:linenos:

.. literalinclude:: ../examples/featherwing_sevensegment_simpletest.py
:caption: examples/featherwing_sevensegment_simpletest.py
:linenos:

Other tests
------------

Expand Down
47 changes: 47 additions & 0 deletions examples/featherwing_sevensegment_simpletest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
"""This example changes the fill, brightness, blink rates,
shows number and text printing, displays a counter
and then shows off the new marquee features."""

from time import sleep
from adafruit_featherwing import sevensegment_featherwing

display = sevensegment_featherwing.SevenSegmentFeatherWing()

#Fill and empty all segments
for count in range(0, 3):
display.fill(True)
sleep(0.5)
display.fill(False)
sleep(0.5)

#Display a number and text
display.print(1234)
sleep(1)
display.print('FEED')

#Change brightness
for brightness in range(0, 16):
display.brightness = brightness
sleep(0.1)

#Change blink rate
for blink_rate in range(3, 0, -1):
display.blink_rate = blink_rate
sleep(4)
display.blink_rate = 0

#Show a counter using decimals
count = 975.0
while count < 1025:
count += 1
display.print(count)
sleep(0.1)

#Display a Time
hour = 12
for minute in range(15, 26):
display.print("{}:{}".format(hour, minute))
sleep(1)

#Show the Marquee
display.marquee('Deadbeef 192.168.100.102... ', 0.2)