From 7f27b57c0976378eab34c65e039b6db4d8de5a1b Mon Sep 17 00:00:00 2001 From: =Dale Weber <=geekguy.wy@gmail.com> Date: Mon, 10 Feb 2020 18:07:31 -0800 Subject: [PATCH 01/11] Adding new animation demo to show what can be done when using set_digit_raw() --- examples/ht16k33_animation_demo.py | 103 +++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 examples/ht16k33_animation_demo.py diff --git a/examples/ht16k33_animation_demo.py b/examples/ht16k33_animation_demo.py new file mode 100644 index 0000000..6bef419 --- /dev/null +++ b/examples/ht16k33_animation_demo.py @@ -0,0 +1,103 @@ +""" Test script for display animations on an HT16K33 with alphanumeric display """ + +import board +import busio +from time import sleep +from adafruit_ht16k33 import segments + +# The number of seconds to delay between writing segments +DEFAULT_CHAR_DELAY_SEC = 0.2 + +# The number of cycles to go for each animation +DEFAULT_CYCLES = 1 + +# +# Segment bits on the HT16K33 with alphanumeric display +# + +N = 16384 +M = 8192 +L = 4096 +K = 2048 +J = 1024 +I = 512 +H = 256 +G2= 128 +G1= 64 +F = 32 +E = 16 +D = 8 +C = 4 +B = 2 +A = 1 + +def animate(digits, bitmasks, delay=DEFAULT_CHAR_DELAY_SEC, cycles=DEFAULT_CYCLES): + ''' + Main driver for alphanumeric display animations (WIP!!!) + Param: digits - a list of the digits to write to, like [0, 1, 3]. The digits are + 0 to 3 starting at the left most digit. Digits will be written to in sequence. + Param: bitmasks - a list of the bitmasks to write, in sequence, to the specified digits. + Param: delay - The delay, in seconds (or fractions of), between writing bitmasks to a digit. + Param: cycles - The number of cycles (loops) to write an animation. + + Returns: No result + ''' + for cy in range(cycles): + for dig in digits: + for bits in bitmasks: + display.set_digit_raw(dig, bits) + sleep(delay) + +def chase_animation(delay=DEFAULT_CHAR_DELAY_SEC, cycles=DEFAULT_CYCLES): + for cy in range(cycles): + animate([0, 1, 2, 3], [A, 0], delay) + animate([3], [B, C, D, 0], delay) + animate([2, 1, 0], [D, 0], delay) + animate([0], [E, F, H, G2, 0], delay) + animate([1, 2], [G1, G2, 0], delay) + animate([3], [G1, J, A, 0], delay) + animate([2, 1], [A, 0], delay) + animate([0], [A, F, E, D, 0], delay) + animate([1, 2], [D, 0], delay) + animate([3], [D, C, B, J, G1, 0], delay) + animate([2, 1], [G2, G1, 0], delay) + animate([0], [H, 0], delay) + #animate([0], [M, H, 0x0], delay) + +# Initialize the I2C bus +i2c = busio.I2C(board.SCL, board.SDA) + +# Initialize the HT16K33 with alphanumeric display featherwing +display = segments.Seg14x4(i2c) + +text = "Init" + +display.fill(1) +sleep(1) +display.fill(0) + +display.print(text) +sleep(1) +display.fill(0) +print() + +while True: + # Arrow + animate([0, 1, 2], [G1+G2]) + animate([3], [G1+H+K]) + sleep(1.5) + display.fill(0) + sleep(1.5) + + # Flying + animate([0], [H+J, G1+G2, K+M, G1+G2], 0.2, 5) + animate([0], [0]) + sleep(1.5) + display.fill(0) + sleep(1.5) + + # Chase and reverse. + chase_animation(0.1, 5) + sleep(1.5) + display.fill(0) + sleep(1.5) From 577963b11a57fcded8aa40dcb3970dd9662d5213 Mon Sep 17 00:00:00 2001 From: =Dale Weber <=geekguy.wy@gmail.com> Date: Mon, 10 Feb 2020 18:25:56 -0800 Subject: [PATCH 02/11] Adding new animation demo to show what can be done by using set_raw_digit() --- examples/ht16k33_animation_demo.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/ht16k33_animation_demo.py b/examples/ht16k33_animation_demo.py index 6bef419..6efe349 100644 --- a/examples/ht16k33_animation_demo.py +++ b/examples/ht16k33_animation_demo.py @@ -34,13 +34,13 @@ def animate(digits, bitmasks, delay=DEFAULT_CHAR_DELAY_SEC, cycles=DEFAULT_CYCLES): ''' Main driver for alphanumeric display animations (WIP!!!) - Param: digits - a list of the digits to write to, like [0, 1, 3]. The digits are + Param: digits - a list of the digits to write to, like [0, 1, 3]. The digits are 0 to 3 starting at the left most digit. Digits will be written to in sequence. Param: bitmasks - a list of the bitmasks to write, in sequence, to the specified digits. Param: delay - The delay, in seconds (or fractions of), between writing bitmasks to a digit. Param: cycles - The number of cycles (loops) to write an animation. - Returns: No result + Returns: No result ''' for cy in range(cycles): for dig in digits: @@ -95,7 +95,7 @@ def chase_animation(delay=DEFAULT_CHAR_DELAY_SEC, cycles=DEFAULT_CYCLES): sleep(1.5) display.fill(0) sleep(1.5) - + # Chase and reverse. chase_animation(0.1, 5) sleep(1.5) From 474437feb28faad7d1aec9ec82f318a547e60070 Mon Sep 17 00:00:00 2001 From: =Dale Weber <=geekguy.wy@gmail.com> Date: Mon, 10 Feb 2020 18:36:20 -0800 Subject: [PATCH 03/11] Converted all tabs to spaces for indentation. --- examples/ht16k33_animation_demo.py | 108 ++++++++++++++--------------- 1 file changed, 54 insertions(+), 54 deletions(-) diff --git a/examples/ht16k33_animation_demo.py b/examples/ht16k33_animation_demo.py index 6efe349..af9320a 100644 --- a/examples/ht16k33_animation_demo.py +++ b/examples/ht16k33_animation_demo.py @@ -5,14 +5,14 @@ from time import sleep from adafruit_ht16k33 import segments -# The number of seconds to delay between writing segments +# The number of seconds to delay between writing segments DEFAULT_CHAR_DELAY_SEC = 0.2 -# The number of cycles to go for each animation +# The number of cycles to go for each animation DEFAULT_CYCLES = 1 # -# Segment bits on the HT16K33 with alphanumeric display +# Segment bits on the HT16K33 with alphanumeric display # N = 16384 @@ -32,42 +32,42 @@ A = 1 def animate(digits, bitmasks, delay=DEFAULT_CHAR_DELAY_SEC, cycles=DEFAULT_CYCLES): - ''' - Main driver for alphanumeric display animations (WIP!!!) - Param: digits - a list of the digits to write to, like [0, 1, 3]. The digits are - 0 to 3 starting at the left most digit. Digits will be written to in sequence. - Param: bitmasks - a list of the bitmasks to write, in sequence, to the specified digits. - Param: delay - The delay, in seconds (or fractions of), between writing bitmasks to a digit. - Param: cycles - The number of cycles (loops) to write an animation. - - Returns: No result - ''' - for cy in range(cycles): - for dig in digits: - for bits in bitmasks: - display.set_digit_raw(dig, bits) - sleep(delay) + ''' + Main driver for alphanumeric display animations (WIP!!!) + Param: digits - a list of the digits to write to, like [0, 1, 3]. The digits are + 0 to 3 starting at the left most digit. Digits will be written to in sequence. + Param: bitmasks - a list of the bitmasks to write, in sequence, to the specified digits. + Param: delay - The delay, in seconds (or fractions of), between writing bitmasks to a digit. + Param: cycles - The number of cycles (loops) to write an animation. + + Returns: No result + ''' + for cy in range(cycles): + for dig in digits: + for bits in bitmasks: + display.set_digit_raw(dig, bits) + sleep(delay) def chase_animation(delay=DEFAULT_CHAR_DELAY_SEC, cycles=DEFAULT_CYCLES): - for cy in range(cycles): - animate([0, 1, 2, 3], [A, 0], delay) - animate([3], [B, C, D, 0], delay) - animate([2, 1, 0], [D, 0], delay) - animate([0], [E, F, H, G2, 0], delay) - animate([1, 2], [G1, G2, 0], delay) - animate([3], [G1, J, A, 0], delay) - animate([2, 1], [A, 0], delay) - animate([0], [A, F, E, D, 0], delay) - animate([1, 2], [D, 0], delay) - animate([3], [D, C, B, J, G1, 0], delay) - animate([2, 1], [G2, G1, 0], delay) - animate([0], [H, 0], delay) - #animate([0], [M, H, 0x0], delay) - -# Initialize the I2C bus + for cy in range(cycles): + animate([0, 1, 2, 3], [A, 0], delay) + animate([3], [B, C, D, 0], delay) + animate([2, 1, 0], [D, 0], delay) + animate([0], [E, F, H, G2, 0], delay) + animate([1, 2], [G1, G2, 0], delay) + animate([3], [G1, J, A, 0], delay) + animate([2, 1], [A, 0], delay) + animate([0], [A, F, E, D, 0], delay) + animate([1, 2], [D, 0], delay) + animate([3], [D, C, B, J, G1, 0], delay) + animate([2, 1], [G2, G1, 0], delay) + animate([0], [H, 0], delay) + #animate([0], [M, H, 0x0], delay) + +# Initialize the I2C bus i2c = busio.I2C(board.SCL, board.SDA) -# Initialize the HT16K33 with alphanumeric display featherwing +# Initialize the HT16K33 with alphanumeric display featherwing display = segments.Seg14x4(i2c) text = "Init" @@ -82,22 +82,22 @@ def chase_animation(delay=DEFAULT_CHAR_DELAY_SEC, cycles=DEFAULT_CYCLES): print() while True: - # Arrow - animate([0, 1, 2], [G1+G2]) - animate([3], [G1+H+K]) - sleep(1.5) - display.fill(0) - sleep(1.5) - - # Flying - animate([0], [H+J, G1+G2, K+M, G1+G2], 0.2, 5) - animate([0], [0]) - sleep(1.5) - display.fill(0) - sleep(1.5) - - # Chase and reverse. - chase_animation(0.1, 5) - sleep(1.5) - display.fill(0) - sleep(1.5) + # Arrow + animate([0, 1, 2], [G1+G2]) + animate([3], [G1+H+K]) + sleep(1.5) + display.fill(0) + sleep(1.5) + + # Flying + animate([0], [H+J, G1+G2, K+M, G1+G2], 0.2, 5) + animate([0], [0]) + sleep(1.5) + display.fill(0) + sleep(1.5) + + # Chase and reverse. + chase_animation(0.1, 5) + sleep(1.5) + display.fill(0) + sleep(1.5) From 3c5cab72b6467fc08f7b3463fb01a3aeda2c1783 Mon Sep 17 00:00:00 2001 From: =Dale Weber <=geekguy.wy@gmail.com> Date: Mon, 10 Feb 2020 18:59:23 -0800 Subject: [PATCH 04/11] Rewrote two for loops to be while loops. --- examples/ht16k33_animation_demo.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/examples/ht16k33_animation_demo.py b/examples/ht16k33_animation_demo.py index af9320a..8b27311 100644 --- a/examples/ht16k33_animation_demo.py +++ b/examples/ht16k33_animation_demo.py @@ -1,8 +1,8 @@ """ Test script for display animations on an HT16K33 with alphanumeric display """ +from time import sleep import board import busio -from time import sleep from adafruit_ht16k33 import segments # The number of seconds to delay between writing segments @@ -42,14 +42,22 @@ def animate(digits, bitmasks, delay=DEFAULT_CHAR_DELAY_SEC, cycles=DEFAULT_CYCLE Returns: No result ''' - for cy in range(cycles): + cy = 0 + + while cy < cycles: + # cy in range(cycles): for dig in digits: for bits in bitmasks: display.set_digit_raw(dig, bits) sleep(delay) + + cy += 1 def chase_animation(delay=DEFAULT_CHAR_DELAY_SEC, cycles=DEFAULT_CYCLES): - for cy in range(cycles): + cy = 0 + + while cy < cycles: + #for cy in range(cycles): animate([0, 1, 2, 3], [A, 0], delay) animate([3], [B, C, D, 0], delay) animate([2, 1, 0], [D, 0], delay) @@ -63,6 +71,8 @@ def chase_animation(delay=DEFAULT_CHAR_DELAY_SEC, cycles=DEFAULT_CYCLES): animate([2, 1], [G2, G1, 0], delay) animate([0], [H, 0], delay) #animate([0], [M, H, 0x0], delay) + + cy += 1 # Initialize the I2C bus i2c = busio.I2C(board.SCL, board.SDA) From 8595bed1699390f8ec529bbb6669383d39a5fd75 Mon Sep 17 00:00:00 2001 From: =Dale Weber <=geekguy.wy@gmail.com> Date: Mon, 10 Feb 2020 19:03:16 -0800 Subject: [PATCH 05/11] Removed trailing white space. --- examples/ht16k33_animation_demo.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/ht16k33_animation_demo.py b/examples/ht16k33_animation_demo.py index 8b27311..1221917 100644 --- a/examples/ht16k33_animation_demo.py +++ b/examples/ht16k33_animation_demo.py @@ -50,12 +50,12 @@ def animate(digits, bitmasks, delay=DEFAULT_CHAR_DELAY_SEC, cycles=DEFAULT_CYCLE for bits in bitmasks: display.set_digit_raw(dig, bits) sleep(delay) - + cy += 1 def chase_animation(delay=DEFAULT_CHAR_DELAY_SEC, cycles=DEFAULT_CYCLES): cy = 0 - + while cy < cycles: #for cy in range(cycles): animate([0, 1, 2, 3], [A, 0], delay) @@ -71,7 +71,7 @@ def chase_animation(delay=DEFAULT_CHAR_DELAY_SEC, cycles=DEFAULT_CYCLES): animate([2, 1], [G2, G1, 0], delay) animate([0], [H, 0], delay) #animate([0], [M, H, 0x0], delay) - + cy += 1 # Initialize the I2C bus From 445c7401ec969a8fcd03c6f9235be4575a3e9b46 Mon Sep 17 00:00:00 2001 From: =Dale Weber <=geekguy.wy@gmail.com> Date: Mon, 10 Feb 2020 19:32:00 -0800 Subject: [PATCH 06/11] Added ht16k33_animation_demo.py (NEW) and ht16k33_matrix_pillow_image.py (was missing) to docs/examples.rst --- docs/examples.rst | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/docs/examples.rst b/docs/examples.rst index 6744dae..7216adc 100644 --- a/docs/examples.rst +++ b/docs/examples.rst @@ -14,3 +14,11 @@ Ensure your device works with this simple test. .. literalinclude:: ../examples/ht16k33_bicolor24_simpletest.py :caption: examples/ht16k33_bicolor24_simpletest.py :linenos: + +.. literalinclude:: ../examples/ht16k33_matrix_pillow_image.py + :caption: examples/ht16k33_matrix_pillow_image.py + :linenos: + +.. literalinclude:: ../examples/ht16k33_animation_demo.py + :caption: examples/ht16k33_animation_demo.py + :linenos: From b7743acce8cc11e68660f3159ad0cc6558ecd618 Mon Sep 17 00:00:00 2001 From: =Dale Weber <=geekguy.wy@gmail.com> Date: Thu, 13 Feb 2020 04:23:11 -0800 Subject: [PATCH 07/11] Upgraded version of ht16k33_animation_demo.py --- examples/ht16k33_animation_demo.py | 147 ++++++++--------------------- 1 file changed, 41 insertions(+), 106 deletions(-) diff --git a/examples/ht16k33_animation_demo.py b/examples/ht16k33_animation_demo.py index 1221917..c383f92 100644 --- a/examples/ht16k33_animation_demo.py +++ b/examples/ht16k33_animation_demo.py @@ -1,113 +1,48 @@ -""" Test script for display animations on an HT16K33 with alphanumeric display """ - +#!/usr/bin/env python3 +from os import environ, system +from posixpath import isdir, isfile from time import sleep -import board -import busio -from adafruit_ht16k33 import segments - -# The number of seconds to delay between writing segments -DEFAULT_CHAR_DELAY_SEC = 0.2 - -# The number of cycles to go for each animation -DEFAULT_CYCLES = 1 - -# -# Segment bits on the HT16K33 with alphanumeric display -# - -N = 16384 -M = 8192 -L = 4096 -K = 2048 -J = 1024 -I = 512 -H = 256 -G2= 128 -G1= 64 -F = 32 -E = 16 -D = 8 -C = 4 -B = 2 -A = 1 - -def animate(digits, bitmasks, delay=DEFAULT_CHAR_DELAY_SEC, cycles=DEFAULT_CYCLES): - ''' - Main driver for alphanumeric display animations (WIP!!!) - Param: digits - a list of the digits to write to, like [0, 1, 3]. The digits are - 0 to 3 starting at the left most digit. Digits will be written to in sequence. - Param: bitmasks - a list of the bitmasks to write, in sequence, to the specified digits. - Param: delay - The delay, in seconds (or fractions of), between writing bitmasks to a digit. - Param: cycles - The number of cycles (loops) to write an animation. - - Returns: No result - ''' - cy = 0 - - while cy < cycles: - # cy in range(cycles): - for dig in digits: - for bits in bitmasks: - display.set_digit_raw(dig, bits) - sleep(delay) - - cy += 1 +import subprocess -def chase_animation(delay=DEFAULT_CHAR_DELAY_SEC, cycles=DEFAULT_CYCLES): - cy = 0 +HOME = environ["HOME"] +print("HOME = {0}".format(HOME)) - while cy < cycles: - #for cy in range(cycles): - animate([0, 1, 2, 3], [A, 0], delay) - animate([3], [B, C, D, 0], delay) - animate([2, 1, 0], [D, 0], delay) - animate([0], [E, F, H, G2, 0], delay) - animate([1, 2], [G1, G2, 0], delay) - animate([3], [G1, J, A, 0], delay) - animate([2, 1], [A, 0], delay) - animate([0], [A, F, E, D, 0], delay) - animate([1, 2], [D, 0], delay) - animate([3], [D, C, B, J, G1, 0], delay) - animate([2, 1], [G2, G1, 0], delay) - animate([0], [H, 0], delay) - #animate([0], [M, H, 0x0], delay) +FROM_DIR = "{0}/Downloads/OS/Circuitpython/Libraries/bundle/lib".format(HOME) +TO_DIR = "{0}/Downloads/OS/Circuitpython/Libraries/lib".format(HOME) +ORIGINAL_DIR = "/media/hybotics/DISPLAYPY/lib/" - cy += 1 - -# Initialize the I2C bus -i2c = busio.I2C(board.SCL, board.SDA) - -# Initialize the HT16K33 with alphanumeric display featherwing -display = segments.Seg14x4(i2c) - -text = "Init" - -display.fill(1) -sleep(1) -display.fill(0) - -display.print(text) -sleep(1) -display.fill(0) +LIST = subprocess.getoutput("dir {0}".format(ORIGINAL_DIR)).strip() +print("LIST = '{0}'".format(LIST)) print() -while True: - # Arrow - animate([0, 1, 2], [G1+G2]) - animate([3], [G1+H+K]) - sleep(1.5) - display.fill(0) - sleep(1.5) - - # Flying - animate([0], [H+J, G1+G2, K+M, G1+G2], 0.2, 5) - animate([0], [0]) - sleep(1.5) - display.fill(0) - sleep(1.5) +LIST = LIST.split() +print("LIST = '{0}'".format(LIST)) +print() - # Chase and reverse. - chase_animation(0.1, 5) - sleep(1.5) - display.fill(0) - sleep(1.5) +print("FROM_DIR = '{0}'".format(FROM_DIR)) +print("TO_DIR = '{0}'".format(TO_DIR)) +print() +sleep(5) + +for FILE in LIST: + FILE = FILE.strip() + print("FILE = '{0}'".format(FILE)) + FN = ("{0}/{1}").format(FROM_DIR, FILE) + + print("FN = '{0}'".format(FN)) + + if (isdir(FN)): + print("COPYING DIRECTORY '{0}' to '{1}'".format(FN, TO_DIR)) + command = "cp -rf {0} {1}".format(FN, TO_DIR) + #print("command = '{0}'".format(command)) + system(command) + elif (isfile(FN)): + print("COPYING FILE '{0}' to '{1}'".format(FN, TO_DIR)) + command = "cp {0} {1}".format(FN, TO_DIR) + #print("command = '{0}'".format(command)) + system(command) + else: + print("File is not a directory or file!") + + print() + sleep(1) From 27ab7c7605b1afe8350bf02b4344434c0d39d8ae Mon Sep 17 00:00:00 2001 From: =Dale Weber <=geekguy.wy@gmail.com> Date: Thu, 13 Feb 2020 04:41:25 -0800 Subject: [PATCH 08/11] Added wrong file on last commit. This is the correct file. --- examples/ht16k33_animation_demo.py | 360 +++++++++++++++++++++++++---- 1 file changed, 316 insertions(+), 44 deletions(-) diff --git a/examples/ht16k33_animation_demo.py b/examples/ht16k33_animation_demo.py index c383f92..34e537d 100644 --- a/examples/ht16k33_animation_demo.py +++ b/examples/ht16k33_animation_demo.py @@ -1,48 +1,320 @@ -#!/usr/bin/env python3 -from os import environ, system -from posixpath import isdir, isfile +""" + Test script for display animations on an HT16K33 with alphanumeric display + + The display must be initialized with auto_write=False. +""" + +# +# Segment bits on the HT16K33 with alphanumeric display. +# +# Add the values of the segments you need to create a bitmask +# + +N = 16384 +M = 8192 +L = 4096 +K = 2048 +J = 1024 +I = 512 +H = 256 +G2= 128 +G1= 64 +F = 32 +E = 16 +D = 8 +C = 4 +B = 2 +A = 1 + +# The number of seconds to delay between writing segments +DEFAULT_CHAR_DELAY_SEC = 0.2 + +# The number of cycles to go for each animation +DEFAULT_CYCLES = 5 + +# Brightness of the display (0 to 15) +DEFAULT_DISPLAY_BRIGHTNESS = 2 + from time import sleep -import subprocess - -HOME = environ["HOME"] -print("HOME = {0}".format(HOME)) - -FROM_DIR = "{0}/Downloads/OS/Circuitpython/Libraries/bundle/lib".format(HOME) -TO_DIR = "{0}/Downloads/OS/Circuitpython/Libraries/lib".format(HOME) -ORIGINAL_DIR = "/media/hybotics/DISPLAYPY/lib/" - -LIST = subprocess.getoutput("dir {0}".format(ORIGINAL_DIR)).strip() -print("LIST = '{0}'".format(LIST)) -print() - -LIST = LIST.split() -print("LIST = '{0}'".format(LIST)) -print() - -print("FROM_DIR = '{0}'".format(FROM_DIR)) -print("TO_DIR = '{0}'".format(TO_DIR)) -print() -sleep(5) - -for FILE in LIST: - FILE = FILE.strip() - print("FILE = '{0}'".format(FILE)) - FN = ("{0}/{1}").format(FROM_DIR, FILE) - - print("FN = '{0}'".format(FN)) - - if (isdir(FN)): - print("COPYING DIRECTORY '{0}' to '{1}'".format(FN, TO_DIR)) - command = "cp -rf {0} {1}".format(FN, TO_DIR) - #print("command = '{0}'".format(command)) - system(command) - elif (isfile(FN)): - print("COPYING FILE '{0}' to '{1}'".format(FN, TO_DIR)) - command = "cp {0} {1}".format(FN, TO_DIR) - #print("command = '{0}'".format(command)) - system(command) +import board +import busio +from adafruit_ht16k33.segments import Seg14x4 + +# Initialize the I2C bus +i2c = busio.I2C(board.SCL, board.SDA) + +# Initialize the HT16K33 with alphanumeric display featherwing. +# +# You MUST set auto_write=False +display = Seg14x4(i2c, auto_write=False) +display.brightness = DEFAULT_DISPLAY_BRIGHTNESS + +def animate(digits, bitmasks, delay=DEFAULT_CHAR_DELAY_SEC, auto_write=True): + ''' + Main driver for all alphanumeric display animations (WIP!!!) + Param: digits - a list of the digits to write to, in order, like [0, 1, 3]. The digits are + 0 to 3 starting at the left most digit. + Param: bitmasks - a list of the bitmasks to write, in sequence, to the specified digits. + Param: delay - The delay, in seconds (or fractions of), between writing bitmasks to a digit. + Param: auto_write - Whether to actually write to the display immediately or not. + + Returns: Nothing + ''' + if not isinstance(digits, list): + raise ValueError("The first parameter MUST be a list!") + elif not isinstance(bitmasks, list): + raise ValueError("The second parameter MUST be a list!") + elif delay < 0: + raise ValueError("The delay between frames must be positive!") else: - print("File is not a directory or file!") + for dig in digits: + for bits in bitmasks: + display.set_digit_raw(dig, bits) + + if auto_write: + display.show() + sleep(delay) + +def chase_forward_and_reverse(delay=DEFAULT_CHAR_DELAY_SEC, cycles=DEFAULT_CYCLES): + cy = 0 + + while cy < cycles: + animate([0, 1, 2, 3], [A, 0], delay) + animate([3], [B, C, D, 0], delay) + animate([2, 1, 0], [D, 0], delay) + animate([0], [E, F, H, G2, 0], delay) + animate([1, 2], [G1, G2, 0], delay) + animate([3], [G1, J, A, 0], delay) + animate([2, 1], [A, 0], delay) + animate([0], [A, F, E, D, 0], delay) + animate([1, 2], [D, 0], delay) + animate([3], [D, C, B, J, G1, 0], delay) + animate([2, 1], [G2, G1, 0], delay) + animate([0], [H, 0], delay) + + cy += 1 + +def prelude_to_spinners(delay=DEFAULT_CHAR_DELAY_SEC, cycles=DEFAULT_CYCLES): + cy = 0 + auto_write = False + + while cy < cycles: + animate([1, 2], [A], 0, auto_write) + display.show() + sleep(delay) + + animate([0, 3], [A], 0, auto_write) + display.show() + sleep(delay) + + animate([0], [A+F], 0, auto_write) + animate([3], [A+B], 0, auto_write) + display.show() + sleep(delay) + + animate([0], [A+E+F], 0, auto_write) + animate([3], [A+B+C], 0, auto_write) + display.show() + sleep(delay) + + animate([0], [A+D+E+F], 0, auto_write) + animate([3], [A+B+C+D], 0, auto_write) + display.show() + sleep(delay) + + animate([1], [A+D], 0, auto_write) + animate([2], [A+D], 0, auto_write) + display.show() + sleep(delay) + + animate([1], [A+D+M], 0, auto_write) + animate([2], [A+D+K], 0, auto_write) + display.show() + sleep(delay) + + animate([1], [A+D+M+H], 0, auto_write) + animate([2], [A+D+K+J], 0, auto_write) + display.show() + sleep(delay) + + animate([0], [A+E+F+J+D], 0, auto_write) + animate([3], [A+B+C+H+D], 0, auto_write) + display.show() + sleep(delay) + + animate([0], [A+E+F+J+K+D], 0, auto_write) + animate([3], [A+B+C+H+M+D], 0, auto_write) + display.show() + sleep(delay) + + display.fill(0) + display.show() + sleep(delay) + + cy += 1 + +def spinners(delay=DEFAULT_CHAR_DELAY_SEC, cycles=DEFAULT_CYCLES): + cy = 0 + auto_write = False + + while cy < cycles: + animate([0], [H+M], 0, auto_write) + animate([1], [J+K], 0, auto_write) + animate([2], [H+M], 0, auto_write) + animate([3], [J+K], 0, auto_write) + display.show() + sleep(delay) + + animate([0], [G1+G2], 0, auto_write) + animate([1], [G1+G2], 0, auto_write) + animate([2], [G1+G2], 0, auto_write) + animate([3], [G1+G2], 0, auto_write) + display.show() + sleep(delay) + + animate([0], [J+K], 0, auto_write) + animate([1], [H+M], 0, auto_write) + animate([2], [J+K], 0, auto_write) + animate([3], [H+M], 0, auto_write) + display.show() + sleep(delay) + + cy += 1 + + display.fill(0) + +def enclosed_spinners(delay=DEFAULT_CHAR_DELAY_SEC, cycles=DEFAULT_CYCLES): + cy = 0 + auto_write = False + + while cy < cycles: + animate([0], [A+D+E+F+H+M], 0, auto_write) + animate([1], [A+D+J+K], 0, auto_write) + animate([2], [A+D+H+M], 0, auto_write) + animate([3], [A+B+C+D+J+K], 0, auto_write) + display.show() + sleep(delay) + + animate([0], [A+D+E+F+G1+G2], 0, auto_write) + animate([1], [A+D+G1+G2], 0, auto_write) + animate([2], [A+D+G1+G2], 0, auto_write) + animate([3], [A+B+C+D+G1+G2], 0, auto_write) + display.show() + sleep(delay) + + animate([0], [A+D+E+F+J+K], 0, auto_write) + animate([1], [A+D+H+M], 0, auto_write) + animate([2], [A+D+J+K], 0, auto_write) + animate([3], [A+B+C+D+H+M], 0, auto_write) + display.show() + sleep(delay) + + cy += 1 + + display.fill(0) + +def count_down(delay=DEFAULT_CHAR_DELAY_SEC, cycles=DEFAULT_CYCLES): + auto_write = False + numbers = [ [A+B+C+D+G1+G2+N], [A+B+D+E+G1+G2+N], [B+C+N] ] + index = 0 + + display.fill(0) + + while index < len(numbers): + animate([index], numbers[index], 0, auto_write) + display.show() + sleep(1) + display.fill(0) + sleep(0.5) + + index += 1 - print() sleep(1) + display.fill(0) + +try: + text = "Init" + + display.fill(1) + display.show() + sleep(1) + display.fill(0) + display.show() + + display.print(text) + display.show() + sleep(2) + display.fill(0) + display.show() + sleep(1) + + count_down(0.1, 1) + sleep(0.2) + + text = "Go!!" + + display.print(text) + display.show() + sleep(1.5) + display.fill(0) + display.show() + sleep(0.5) + print() + + while True: + # Arrow + print("Arrow") + animate([0, 1, 2], [G1+G2], 0.1) + animate([3], [G1+H+K], 0.1) + sleep(1.0) + display.fill(0) + sleep(1.0) + + # Flying + print("Flying") + cy = 0 + + while cy < DEFAULT_CYCLES: + animate([0], [H+J, G1+G2, K+M, G1+G2], DEFAULT_CHAR_DELAY_SEC) + + cy += 1 + + animate([0], [0]) + sleep(1.0) + display.fill(0) + sleep(1.0) + + # Chase forward and reverse. + print("Chase forward and reverse") + chase_forward_and_reverse(0.01, 5) + sleep(1.0) + display.fill(0) + sleep(1.0) + + # Testing writing to more than one segment simultaneously + print("Prelude to Spinners") + prelude_to_spinners(0.1, 5) + sleep(1.0) + display.fill(0) + display.show() + sleep(1.0) + + print("Spinners") + spinners(0.1, 20) + sleep(1.0) + display.fill(0) + display.show() + sleep(1.0) + + + print("Enclosed Spinners") + enclosed_spinners(0.1, 20) + sleep(1.0) + display.fill(0) + display.show() + sleep(1.0) + + print() +except KeyboardInterrupt: + display.fill(0) + display.show() From 4d5edad437d55cf45ec7c995a5ad33acd14f0a3f Mon Sep 17 00:00:00 2001 From: =Dale Weber <=geekguy.wy@gmail.com> Date: Thu, 13 Feb 2020 04:53:06 -0800 Subject: [PATCH 09/11] Removed trailing spaces and two unused parameters to count_down(). Changed name of cy in line 275 to cyc. --- examples/ht16k33_animation_demo.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/examples/ht16k33_animation_demo.py b/examples/ht16k33_animation_demo.py index 34e537d..5c4c0e7 100644 --- a/examples/ht16k33_animation_demo.py +++ b/examples/ht16k33_animation_demo.py @@ -77,7 +77,7 @@ def animate(digits, bitmasks, delay=DEFAULT_CHAR_DELAY_SEC, auto_write=True): def chase_forward_and_reverse(delay=DEFAULT_CHAR_DELAY_SEC, cycles=DEFAULT_CYCLES): cy = 0 - + while cy < cycles: animate([0, 1, 2, 3], [A, 0], delay) animate([3], [B, C, D, 0], delay) @@ -178,7 +178,7 @@ def spinners(delay=DEFAULT_CHAR_DELAY_SEC, cycles=DEFAULT_CYCLES): animate([3], [H+M], 0, auto_write) display.show() sleep(delay) - + cy += 1 display.fill(0) @@ -208,16 +208,16 @@ def enclosed_spinners(delay=DEFAULT_CHAR_DELAY_SEC, cycles=DEFAULT_CYCLES): animate([3], [A+B+C+D+H+M], 0, auto_write) display.show() sleep(delay) - + cy += 1 display.fill(0) -def count_down(delay=DEFAULT_CHAR_DELAY_SEC, cycles=DEFAULT_CYCLES): +def count_down(): auto_write = False numbers = [ [A+B+C+D+G1+G2+N], [A+B+D+E+G1+G2+N], [B+C+N] ] index = 0 - + display.fill(0) while index < len(numbers): @@ -248,7 +248,7 @@ def count_down(delay=DEFAULT_CHAR_DELAY_SEC, cycles=DEFAULT_CYCLES): display.show() sleep(1) - count_down(0.1, 1) + count_down() sleep(0.2) text = "Go!!" @@ -272,13 +272,13 @@ def count_down(delay=DEFAULT_CHAR_DELAY_SEC, cycles=DEFAULT_CYCLES): # Flying print("Flying") - cy = 0 + cyc = 0 - while cy < DEFAULT_CYCLES: + while cyc < DEFAULT_CYCLES: animate([0], [H+J, G1+G2, K+M, G1+G2], DEFAULT_CHAR_DELAY_SEC) - cy += 1 - + cyc += 1 + animate([0], [0]) sleep(1.0) display.fill(0) @@ -290,7 +290,7 @@ def count_down(delay=DEFAULT_CHAR_DELAY_SEC, cycles=DEFAULT_CYCLES): sleep(1.0) display.fill(0) sleep(1.0) - + # Testing writing to more than one segment simultaneously print("Prelude to Spinners") prelude_to_spinners(0.1, 5) @@ -299,7 +299,7 @@ def count_down(delay=DEFAULT_CHAR_DELAY_SEC, cycles=DEFAULT_CYCLES): display.show() sleep(1.0) - print("Spinners") + print("Spinners") spinners(0.1, 20) sleep(1.0) display.fill(0) From 30d49911b78c28e333a4541ab93268590bc64c6b Mon Sep 17 00:00:00 2001 From: =Dale Weber <=geekguy.wy@gmail.com> Date: Thu, 13 Feb 2020 04:59:57 -0800 Subject: [PATCH 10/11] Removed the last trailing white space and moved imports to the top of the file. --- examples/ht16k33_animation_demo.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/ht16k33_animation_demo.py b/examples/ht16k33_animation_demo.py index 5c4c0e7..82bd86a 100644 --- a/examples/ht16k33_animation_demo.py +++ b/examples/ht16k33_animation_demo.py @@ -4,6 +4,11 @@ The display must be initialized with auto_write=False. """ +from time import sleep +import board +import busio +from adafruit_ht16k33.segments import Seg14x4 + # # Segment bits on the HT16K33 with alphanumeric display. # @@ -35,11 +40,6 @@ # Brightness of the display (0 to 15) DEFAULT_DISPLAY_BRIGHTNESS = 2 -from time import sleep -import board -import busio -from adafruit_ht16k33.segments import Seg14x4 - # Initialize the I2C bus i2c = busio.I2C(board.SCL, board.SDA) @@ -307,7 +307,7 @@ def count_down(): sleep(1.0) - print("Enclosed Spinners") + print("Enclosed Spinners") enclosed_spinners(0.1, 20) sleep(1.0) display.fill(0) From 32b3bb5bb41cf269ba358e926962440aa1111c7c Mon Sep 17 00:00:00 2001 From: =Dale Weber <=geekguy.wy@gmail.com> Date: Fri, 14 Feb 2020 18:03:25 -0800 Subject: [PATCH 11/11] Added error checking for digit and bitmask value in Seg14x4.set_digit_raw() --- adafruit_ht16k33/segments.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/adafruit_ht16k33/segments.py b/adafruit_ht16k33/segments.py index 7c63816..e16e502 100755 --- a/adafruit_ht16k33/segments.py +++ b/adafruit_ht16k33/segments.py @@ -265,7 +265,10 @@ def set_digit_raw(self, index, bitmask): If can be passed as an integer, list, or tuple """ if not 0 <= index <= 3: - return + raise ValueError('Digit value must be an integer in the range: 0-3') + + if not 0 <= bitmask <= 0xFFFF: + raise ValueError('Bitmask value must be an integer in the range: 0-65535') if isinstance(bitmask, (tuple, list)): bitmask = bitmask[0] << 8 | bitmask[1]