From aa377ea55df32fdc9605b2751e64c3256cfd010a Mon Sep 17 00:00:00 2001 From: Benjamyn Love Date: Sun, 6 Feb 2022 22:04:19 +1100 Subject: [PATCH] Changed the menu to a list --- backup.py | 25 +++++++++++++++---------- code.py | 13 ++++--------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/backup.py b/backup.py index 080218a..a38c20d 100644 --- a/backup.py +++ b/backup.py @@ -1,6 +1,15 @@ -# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries -# SPDX-License-Identifier: Unlicense -"""CircuitPython I2C Device Address Scan""" +# Benjamyn Love +# Basic encoder controlled menu for setting the onboard neopixel +# For the kb2040 + +# Pin connections +# encoder_sw -> D3 +# encoder_dt -> D4 +# encoder_clk -> D5 +# I2C_data -> A3 +# I2C_clock -> A2 + + import math import board import adafruit_ssd1306 @@ -39,11 +48,11 @@ sub_menu = False while True: if menu_item == 0: menu = "[R] G B !" - if menu_item == 1: + elif menu_item == 1: menu = "R [G] B !" - if menu_item == 2: + elif menu_item == 2: menu = "R G [B] !" - if menu_item == 3: + elif menu_item == 3: menu = "R G B [!]" # Get neopixel colour value current_r, current_g, current_b = neopixel[0] @@ -98,17 +107,13 @@ while True: if not (current_b - 1) < 0: current_b -= 1 elif menu_item == 3: - print("here") if not (brightness - 0.01) <= 0: - print("this should lower this") brightness = brightness - 0.01 if not enc_btn.value: sub_menu = not sub_menu time.sleep(0.1) - print(brightness) neopixel.fill((current_r, current_g, current_b)) neopixel.brightness = brightness - print(menu_item, sub_menu) last_position = enc.position diff --git a/code.py b/code.py index e1a0dde..8fc4fdf 100644 --- a/code.py +++ b/code.py @@ -39,6 +39,9 @@ enc_btn.direction = digitalio.Direction.INPUT SMT1 = "Set" SMT2 = "Colour :3" +# Menu list (Faster then if statements) +menu = ["[R] G B !", "R [G] B !", "R G [B] !", "R G B [!]"] + # Start the main loop last_position = None brightness = 1.0 @@ -46,14 +49,6 @@ menu_item = 0 sub_menu = False while True: - if menu_item == 0: - menu = "[R] G B !" - if menu_item == 1: - menu = "R [G] B !" - if menu_item == 2: - menu = "R G [B] !" - if menu_item == 3: - menu = "R G B [!]" # Get neopixel colour value current_r, current_g, current_b = neopixel[0] @@ -62,7 +57,7 @@ while True: # Draw the menu - oled.text(menu, 0, 0, 1) + oled.text(menu[menu_item], 0, 0, 1) oled.text(SMT1 if sub_menu else " ", 100 - len(SMT1), 0, 1) oled.text(SMT2 if sub_menu else " ", 100 - len(SMT2), 10, 1) oled.text(f"{current_r}:{current_g}:{current_b}:{math.floor(neopixel.brightness * 100)}", 0, 10, 1)