From c2d282324a74ea825f5f2533e43439d7dfa7785d Mon Sep 17 00:00:00 2001 From: Liz Date: Fri, 19 May 2023 19:43:30 -0400 Subject: [PATCH 1/6] Adding examples for ANO rotary encoder Adding two examples for the ANO rotary encoder. Ports of the Arduino example code. --- examples/seesaw_ano_rotary_7segment_demo.py | 66 +++++++++++++++++++++ examples/seesaw_ano_rotary_simpletest.py | 61 +++++++++++++++++++ 2 files changed, 127 insertions(+) create mode 100644 examples/seesaw_ano_rotary_7segment_demo.py create mode 100644 examples/seesaw_ano_rotary_simpletest.py diff --git a/examples/seesaw_ano_rotary_7segment_demo.py b/examples/seesaw_ano_rotary_7segment_demo.py new file mode 100644 index 0000000..974973b --- /dev/null +++ b/examples/seesaw_ano_rotary_7segment_demo.py @@ -0,0 +1,66 @@ +# SPDX-FileCopyrightText: 2021 John Furcean +# SPDX-License-Identifier: MIT + +"""I2C ANO rotary encoder simple test example.""" + +import board +from adafruit_seesaw import seesaw, rotaryio, digitalio +from adafruit_ht16k33 import segments + +# For use with the STEMMA connector on QT Py RP2040 +# import busio +# i2c = busio.I2C(board.SCL1, board.SDA1) +# seesaw = seesaw.Seesaw(i2c, 0x49) + +i2c = board.I2C() # uses board.SCL and board.SDA +# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller +seesaw = seesaw.Seesaw(i2c, addr=0x49) +display = segments.Seg14x4(i2c, address=0x70) + +seesaw_product = (seesaw.get_version() >> 16) & 0xFFFF +print("Found product {}".format(seesaw_product)) +if seesaw_product != 5740: + print("Wrong firmware loaded? Expected 5740") + +seesaw.pin_mode(1, seesaw.INPUT_PULLUP) +seesaw.pin_mode(2, seesaw.INPUT_PULLUP) +seesaw.pin_mode(3, seesaw.INPUT_PULLUP) +seesaw.pin_mode(4, seesaw.INPUT_PULLUP) +seesaw.pin_mode(5, seesaw.INPUT_PULLUP) + +select = digitalio.DigitalIO(seesaw, 1) +select_held = False +up = digitalio.DigitalIO(seesaw, 2) +up_held = False +left = digitalio.DigitalIO(seesaw, 3) +left_held = False +down = digitalio.DigitalIO(seesaw, 4) +down_held = False +right = digitalio.DigitalIO(seesaw, 5) +right_held = False + +encoder = rotaryio.IncrementalEncoder(seesaw) +last_position = None + +buttons = [select, up, left, down, right] +button_names = ["Select", "Up", "Left", "Down", "Right"] +button_states = [select_held, up_held, left_held, down_held, right_held] +seven_segment_names = ["SELE", " UP ", "LEFT", "DOWN", "RIGH"] + +while True: + position = encoder.position + + if position != last_position: + last_position = position + display.print(" %s" % str(position)) + print("Position: {}".format(position)) + for b in range(5): + if not buttons[b].value and button_states[b] is False: + button_states[b] = True + display.print(seven_segment_names[b]) + print("%s button pressed" % (button_names[b])) + + if buttons[b].value and button_states[b] is True: + button_states[b] = False + display.print(" ") + print("%s button released" % (button_names[b])) diff --git a/examples/seesaw_ano_rotary_simpletest.py b/examples/seesaw_ano_rotary_simpletest.py new file mode 100644 index 0000000..c62165f --- /dev/null +++ b/examples/seesaw_ano_rotary_simpletest.py @@ -0,0 +1,61 @@ +# SPDX-FileCopyrightText: 2021 John Furcean +# SPDX-License-Identifier: MIT + +"""I2C ANO rotary encoder simple test example.""" + +import board +from adafruit_seesaw import seesaw, rotaryio, digitalio + +# For use with the STEMMA connector on QT Py RP2040 +# import busio +# i2c = busio.I2C(board.SCL1, board.SDA1) +# seesaw = seesaw.Seesaw(i2c, 0x49) + +i2c = board.I2C() # uses board.SCL and board.SDA +# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller +seesaw = seesaw.Seesaw(i2c, addr=0x49) + +seesaw_product = (seesaw.get_version() >> 16) & 0xFFFF +print("Found product {}".format(seesaw_product)) +if seesaw_product != 5740: + print("Wrong firmware loaded? Expected 5740") + +seesaw.pin_mode(1, seesaw.INPUT_PULLUP) +seesaw.pin_mode(2, seesaw.INPUT_PULLUP) +seesaw.pin_mode(3, seesaw.INPUT_PULLUP) +seesaw.pin_mode(4, seesaw.INPUT_PULLUP) +seesaw.pin_mode(5, seesaw.INPUT_PULLUP) + +select = digitalio.DigitalIO(seesaw, 1) +select_held = False +up = digitalio.DigitalIO(seesaw, 2) +up_held = False +left = digitalio.DigitalIO(seesaw, 3) +left_held = False +down = digitalio.DigitalIO(seesaw, 4) +down_held = False +right = digitalio.DigitalIO(seesaw, 5) +right_held = False + +encoder = rotaryio.IncrementalEncoder(seesaw) +last_position = None + +buttons = [select, up, left, down, right] +button_names = ["Select", "Up", "Left", "Down", "Right"] +button_states = [select_held, up_held, left_held, down_held, right_held] + +while True: + position = encoder.position + + if position != last_position: + last_position = position + print("Position: {}".format(position)) + + for b in range(5): + if not buttons[b].value and button_states[b] is False: + button_states[b] = True + print("%s button pressed" % (button_names[b])) + + if buttons[b].value and button_states[b] is True: + button_states[b] = False + print("%s button released" % (button_names[b])) From b33334de17aa1e1cde5b489f7d68dc267d7305ce Mon Sep 17 00:00:00 2001 From: Liz Date: Fri, 19 May 2023 19:46:57 -0400 Subject: [PATCH 2/6] fixing library import order --- examples/seesaw_ano_rotary_7segment_demo.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/seesaw_ano_rotary_7segment_demo.py b/examples/seesaw_ano_rotary_7segment_demo.py index 974973b..7b4c865 100644 --- a/examples/seesaw_ano_rotary_7segment_demo.py +++ b/examples/seesaw_ano_rotary_7segment_demo.py @@ -4,8 +4,8 @@ """I2C ANO rotary encoder simple test example.""" import board -from adafruit_seesaw import seesaw, rotaryio, digitalio from adafruit_ht16k33 import segments +from adafruit_seesaw import seesaw, rotaryio, digitalio # For use with the STEMMA connector on QT Py RP2040 # import busio From 2d69849727553e95266a48616b1a7b7a05d610cf Mon Sep 17 00:00:00 2001 From: Liz Date: Fri, 19 May 2023 19:57:41 -0400 Subject: [PATCH 3/6] update 7 segment description --- examples/seesaw_ano_rotary_7segment_demo.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/seesaw_ano_rotary_7segment_demo.py b/examples/seesaw_ano_rotary_7segment_demo.py index 7b4c865..d5a1a7c 100644 --- a/examples/seesaw_ano_rotary_7segment_demo.py +++ b/examples/seesaw_ano_rotary_7segment_demo.py @@ -1,7 +1,7 @@ # SPDX-FileCopyrightText: 2021 John Furcean # SPDX-License-Identifier: MIT -"""I2C ANO rotary encoder simple test example.""" +"""I2C ANO rotary encoder with 7 segment display example.""" import board from adafruit_ht16k33 import segments From 08ff00005ebe686dd5b59b0ecafeca5e899bbc59 Mon Sep 17 00:00:00 2001 From: Liz Date: Fri, 19 May 2023 21:27:10 -0400 Subject: [PATCH 4/6] updating to use f-strings --- examples/seesaw_ano_rotary_7segment_demo.py | 6 +++--- examples/seesaw_ano_rotary_simpletest.py | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/seesaw_ano_rotary_7segment_demo.py b/examples/seesaw_ano_rotary_7segment_demo.py index d5a1a7c..383076a 100644 --- a/examples/seesaw_ano_rotary_7segment_demo.py +++ b/examples/seesaw_ano_rotary_7segment_demo.py @@ -52,15 +52,15 @@ if position != last_position: last_position = position - display.print(" %s" % str(position)) + display.print(" {}".format(position)) print("Position: {}".format(position)) for b in range(5): if not buttons[b].value and button_states[b] is False: button_states[b] = True display.print(seven_segment_names[b]) - print("%s button pressed" % (button_names[b])) + print("{} button pressed".format(button_names[b])) if buttons[b].value and button_states[b] is True: button_states[b] = False display.print(" ") - print("%s button released" % (button_names[b])) + print("{} button released".format(button_names[b])) diff --git a/examples/seesaw_ano_rotary_simpletest.py b/examples/seesaw_ano_rotary_simpletest.py index c62165f..dc8ce69 100644 --- a/examples/seesaw_ano_rotary_simpletest.py +++ b/examples/seesaw_ano_rotary_simpletest.py @@ -54,8 +54,8 @@ for b in range(5): if not buttons[b].value and button_states[b] is False: button_states[b] = True - print("%s button pressed" % (button_names[b])) + print("{} button pressed".format(button_names[b])) if buttons[b].value and button_states[b] is True: button_states[b] = False - print("%s button released" % (button_names[b])) + print("{} button released".format(button_names[b])) From c481937f4b8152b2333f7acbcdd2c14f0554c37c Mon Sep 17 00:00:00 2001 From: Liz Date: Sun, 21 May 2023 09:47:39 -0400 Subject: [PATCH 5/6] actually updating to use f-strings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit it would be helpful if i actually updated the examples to use f-strings 😅 --- examples/seesaw_ano_rotary_7segment_demo.py | 9 +++++---- examples/seesaw_ano_rotary_simpletest.py | 6 +++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/examples/seesaw_ano_rotary_7segment_demo.py b/examples/seesaw_ano_rotary_7segment_demo.py index 383076a..3bccc2f 100644 --- a/examples/seesaw_ano_rotary_7segment_demo.py +++ b/examples/seesaw_ano_rotary_7segment_demo.py @@ -52,15 +52,16 @@ if position != last_position: last_position = position - display.print(" {}".format(position)) - print("Position: {}".format(position)) + display.print(f" {position}") + print(f"Position: {position}") + for b in range(5): if not buttons[b].value and button_states[b] is False: button_states[b] = True display.print(seven_segment_names[b]) - print("{} button pressed".format(button_names[b])) + print(f"{button_names[b]} button pressed") if buttons[b].value and button_states[b] is True: button_states[b] = False display.print(" ") - print("{} button released".format(button_names[b])) + print(f"{button_names[b]} button released") diff --git a/examples/seesaw_ano_rotary_simpletest.py b/examples/seesaw_ano_rotary_simpletest.py index dc8ce69..1856046 100644 --- a/examples/seesaw_ano_rotary_simpletest.py +++ b/examples/seesaw_ano_rotary_simpletest.py @@ -49,13 +49,13 @@ if position != last_position: last_position = position - print("Position: {}".format(position)) + print(f"Position: {position}") for b in range(5): if not buttons[b].value and button_states[b] is False: button_states[b] = True - print("{} button pressed".format(button_names[b])) + print(f"{button_names[b]} button pressed") if buttons[b].value and button_states[b] is True: button_states[b] = False - print("{} button released".format(button_names[b])) + print(f"{button_names[b]} button released") From 89daaec507fa2f5fa4bd7aa9bedf7e8eae09ac44 Mon Sep 17 00:00:00 2001 From: Liz Date: Mon, 22 May 2023 19:08:27 -0400 Subject: [PATCH 6/6] f-string for seesaw_product --- examples/seesaw_ano_rotary_7segment_demo.py | 2 +- examples/seesaw_ano_rotary_simpletest.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/seesaw_ano_rotary_7segment_demo.py b/examples/seesaw_ano_rotary_7segment_demo.py index 3bccc2f..0930c13 100644 --- a/examples/seesaw_ano_rotary_7segment_demo.py +++ b/examples/seesaw_ano_rotary_7segment_demo.py @@ -18,7 +18,7 @@ display = segments.Seg14x4(i2c, address=0x70) seesaw_product = (seesaw.get_version() >> 16) & 0xFFFF -print("Found product {}".format(seesaw_product)) +print(f"Found product {seesaw_product}") if seesaw_product != 5740: print("Wrong firmware loaded? Expected 5740") diff --git a/examples/seesaw_ano_rotary_simpletest.py b/examples/seesaw_ano_rotary_simpletest.py index 1856046..1fc845e 100644 --- a/examples/seesaw_ano_rotary_simpletest.py +++ b/examples/seesaw_ano_rotary_simpletest.py @@ -16,7 +16,7 @@ seesaw = seesaw.Seesaw(i2c, addr=0x49) seesaw_product = (seesaw.get_version() >> 16) & 0xFFFF -print("Found product {}".format(seesaw_product)) +print(f"Found product {seesaw_product}") if seesaw_product != 5740: print("Wrong firmware loaded? Expected 5740")