Changed the menu to a list
This commit is contained in:
parent
ba1fb5c0b3
commit
aa377ea55d
25
backup.py
25
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
|
||||
|
||||
13
code.py
13
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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user