From 87df53fd9a8fb1ba075380a6085ea1825560287d Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Mon, 28 Jan 2019 23:09:26 -0800 Subject: [PATCH 1/5] Added AlphaNum FeatherWing --- README.rst | 1 + adafruit_featherwing/alphanum_featherwing.py | 169 +++++++++++++++++++ docs/api.rst | 4 + docs/examples.rst | 7 + examples/featherwing_alphanum_simpletest.py | 41 +++++ requirements.txt | 3 +- setup.py | 4 +- 7 files changed, 226 insertions(+), 3 deletions(-) create mode 100755 adafruit_featherwing/alphanum_featherwing.py create mode 100755 examples/featherwing_alphanum_simpletest.py diff --git a/README.rst b/README.rst index 33d5a41..9529071 100644 --- a/README.rst +++ b/README.rst @@ -24,6 +24,7 @@ These drivers depends on: * `Adafruit CircuitPython `_ * `INA219 `_ * `Seesaw `_ +* `HT16K33 `_ Please ensure all dependencies are available on the CircuitPython filesystem. This is easily achieved by downloading diff --git a/adafruit_featherwing/alphanum_featherwing.py b/adafruit_featherwing/alphanum_featherwing.py new file mode 100755 index 0000000..6850fda --- /dev/null +++ b/adafruit_featherwing/alphanum_featherwing.py @@ -0,0 +1,169 @@ +# 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.alphanum_featherwing` +==================================================== + +Helper for using the `14-Segment AlphaNumeric FeatherWing `_. + +* 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 time import sleep + +class AlphaNumFeatherWing: + """Class representing an `Adafruit 14-segment AlphaNumeric FeatherWing + `_. + + 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 to display + :type value: str, 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() + 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 adafruit_featherwing import alphanum_featherwing + from time import sleep + + 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 adafruit_featherwing import alphanum_featherwing + from time import sleep + + 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 adafruit_featherwing import alphanum_featherwing + from time import sleep + + 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.') \ No newline at end of file diff --git a/docs/api.rst b/docs/api.rst index a22e2e5..39b3325 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -6,3 +6,7 @@ .. automodule:: adafruit_featherwing.joy_featherwing :members: + +.. automodule:: adafruit_featherwing.alphanum_featherwing + :members: + diff --git a/docs/examples.rst b/docs/examples.rst index e0ef07b..1669687 100644 --- a/docs/examples.rst +++ b/docs/examples.rst @@ -10,3 +10,10 @@ Ensure your device works with this simple test. .. literalinclude:: ../examples/featherwing_joy_simpletest.py :caption: examples/featherwing_joy_simpletest.py :linenos: + +.. literalinclude:: ../examples/featherwing_alphanum_simpletest.py + :caption: examples/featherwing_alphanum_simpletest.py + :linenos: + + + diff --git a/examples/featherwing_alphanum_simpletest.py b/examples/featherwing_alphanum_simpletest.py new file mode 100755 index 0000000..0d660d4 --- /dev/null +++ b/examples/featherwing_alphanum_simpletest.py @@ -0,0 +1,41 @@ +"""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 alphanum_featherwing + +display = alphanum_featherwing.AlphaNumFeatherWing() + +#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('Text') + +#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) + +#Show the Marquee +display.marquee('This is a really long message!!! ', 0.2) \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 19bd87f..59ab469 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,4 +2,5 @@ Adafruit-Blinka adafruit-circuitpython-busdevice adafruit-circuitpython-register adafruit-circuitpython-ina219 -adafruit-circuitpython-seesaw \ No newline at end of file +adafruit-circuitpython-seesaw +adafruit-circuitpython-ht16k33 diff --git a/setup.py b/setup.py index 919d446..6fae959 100644 --- a/setup.py +++ b/setup.py @@ -37,7 +37,7 @@ install_requires=['Adafruit-Blinka', 'adafruit-circuitpython-busdevice', 'adafruit-circuitpython-register', 'adafruit-circuitpython-ina219', - 'adafruit-circuitpython-seesaw'], + 'adafruit-circuitpython-seesaw', 'adafruit-circuitpython-ht16k33'], # Choose your license license='MIT', @@ -61,4 +61,4 @@ # You can just specify the packages manually here if your project is # simple. Or you can use find_packages(). packages=['adafruit_featherwing'], -) \ No newline at end of file +) From 2dbf36be12200fa9bc5369db31459afdacf8fbce Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Mon, 28 Jan 2019 23:13:38 -0800 Subject: [PATCH 2/5] Fixed PyLint Errors --- adafruit_featherwing/alphanum_featherwing.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/adafruit_featherwing/alphanum_featherwing.py b/adafruit_featherwing/alphanum_featherwing.py index 6850fda..c490088 100755 --- a/adafruit_featherwing/alphanum_featherwing.py +++ b/adafruit_featherwing/alphanum_featherwing.py @@ -31,9 +31,9 @@ __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 time import sleep class AlphaNumFeatherWing: """Class representing an `Adafruit 14-segment AlphaNumeric FeatherWing @@ -78,7 +78,7 @@ def marquee(self, text, delay=0.25, loop=True): if isinstance(text, str): self.fill(False) if loop: - while(True): + while True: self._scroll_marquee(text, delay) else: self._scroll_marquee(text, delay) @@ -166,4 +166,4 @@ def fill(self, fill): self._seg14x4.fill(1 if fill else 0) self._seg14x4.show() else: - raise ValueError('Must set to either True or False.') \ No newline at end of file + raise ValueError('Must set to either True or False.') From 61d44b76eb9bfc3d9702e041fd7d390bac3cbafd Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Mon, 28 Jan 2019 23:16:49 -0800 Subject: [PATCH 3/5] Fixed PyLint Errors --- examples/featherwing_alphanum_simpletest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/featherwing_alphanum_simpletest.py b/examples/featherwing_alphanum_simpletest.py index 0d660d4..fbf5180 100755 --- a/examples/featherwing_alphanum_simpletest.py +++ b/examples/featherwing_alphanum_simpletest.py @@ -38,4 +38,4 @@ sleep(0.1) #Show the Marquee -display.marquee('This is a really long message!!! ', 0.2) \ No newline at end of file +display.marquee('This is a really long message!!! ', 0.2) From 681ae91b2d14ed484e31920b632618363b511bc1 Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Tue, 29 Jan 2019 08:06:50 -0800 Subject: [PATCH 4/5] Fixed SphinxDoc Errors --- adafruit_featherwing/alphanum_featherwing.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/adafruit_featherwing/alphanum_featherwing.py b/adafruit_featherwing/alphanum_featherwing.py index c490088..dc3f3c7 100755 --- a/adafruit_featherwing/alphanum_featherwing.py +++ b/adafruit_featherwing/alphanum_featherwing.py @@ -65,11 +65,12 @@ 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 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() From fb0c4c6bcca17babe45605b07a4c507c4c82ce33 Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Tue, 29 Jan 2019 08:59:21 -0800 Subject: [PATCH 5/5] Fixed some example code blocks --- adafruit_featherwing/alphanum_featherwing.py | 22 +++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/adafruit_featherwing/alphanum_featherwing.py b/adafruit_featherwing/alphanum_featherwing.py index dc3f3c7..75879f3 100755 --- a/adafruit_featherwing/alphanum_featherwing.py +++ b/adafruit_featherwing/alphanum_featherwing.py @@ -48,14 +48,16 @@ def print(self, value): """ Print a number or text to the display - :param value: The text to display - :type value: str, int or float + :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() @@ -75,6 +77,7 @@ def marquee(self, text, delay=0.25, loop=True): display = alphanum_featherwing.AlphaNumFeatherWing() display.marquee('This is some really long text ') + """ if isinstance(text, str): self.fill(False) @@ -93,7 +96,8 @@ def _scroll_marquee(self, text, delay): @property def blink_rate(self): - """Blink Rate returns the current rate that the text blinks. + """ + Blink Rate returns the current rate that the text blinks. 0 = Off 1-3 = Successively slower blink rates @@ -101,8 +105,8 @@ def blink_rate(self): .. code-block:: python - from adafruit_featherwing import alphanum_featherwing from time import sleep + from adafruit_featherwing import alphanum_featherwing display = alphanum_featherwing.AlphaNumFeatherWing() display.print('Text') @@ -111,6 +115,7 @@ def blink_rate(self): display.blink_rate = blink_rate print("Current Blink Rate is {}".format(display.blink_rate)) sleep(4) + """ return self._seg14x4.blink_rate @@ -120,15 +125,16 @@ def blink_rate(self, rate): @property def brightness(self): - """Brightness returns the current display brightness. + """ + 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 adafruit_featherwing import alphanum_featherwing from time import sleep + from adafruit_featherwing import alphanum_featherwing display = alphanum_featherwing.AlphaNumFeatherWing() display.print('Text') @@ -137,6 +143,7 @@ def brightness(self): display.brightness = brightness print("Current Brightness is {}".format(display.brightness)) sleep(0.2) + """ return self._seg14x4.brightness @@ -152,8 +159,8 @@ def fill(self, fill): .. code-block:: python - from adafruit_featherwing import alphanum_featherwing from time import sleep + from adafruit_featherwing import alphanum_featherwing display = alphanum_featherwing.AlphaNumFeatherWing() @@ -162,6 +169,7 @@ def fill(self, fill): sleep(0.5) display.fill(False) sleep(0.5) + """ if isinstance(fill, bool): self._seg14x4.fill(1 if fill else 0)