Added Notes

Added pinout
This commit is contained in:
Benjamyn Love 2022-02-06 21:58:34 +11:00
parent fabccd62bc
commit ba1fb5c0b3
2 changed files with 58 additions and 48 deletions

View File

@ -1,6 +1,7 @@
# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
# SPDX-License-Identifier: Unlicense
"""CircuitPython I2C Device Address Scan"""
import math
import board
import adafruit_ssd1306
import neopixel
@ -25,29 +26,37 @@ enc = rotaryio.IncrementalEncoder(board.D5, board.D4)
enc_btn = digitalio.DigitalInOut(board.D3)
enc_btn.direction = digitalio.Direction.INPUT
# Set strings
SMT1 = "Set"
SMT2 = "Colour :3"
# Start the main loop
last_position = None
colour = [128,128,32]
brightness = 1.0
menu_item = 0
sub_menu = False
while True:
if menu_item == 0:
menu = "[R] G B"
menu = "[R] G B !"
if menu_item == 1:
menu = "R [G] B"
menu = "R [G] B !"
if menu_item == 2:
menu = "R G [B]"
menu = "R G [B] !"
if menu_item == 3:
menu = "R G B [!]"
# Get neopixel colour value
current_r, current_g, current_b = neopixel[0]
# Init the oled
oled.fill(0)
# Draw the menu
oled.text(menu, 0, 0, 1)
oled.text(f"{current_r}:{current_g}:{current_b}", 0, 10, 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)
# Show the oled
oled.show()
@ -68,6 +77,9 @@ while True:
elif menu_item == 2:
if not (current_b + 1) > 255:
current_b += 1
elif menu_item == 3:
if not (brightness + 0.01) >= 1:
brightness += 0.01
# If we went left
elif enc.position < last_position:
@ -85,44 +97,18 @@ while True:
elif menu_item == 2:
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
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]"
oled.fill(0)
oled.text(menu, 0, 0, 1)
current_value = neopixel[0]
oled.text(f"{current_value[0]}:{current_value[1]}:{current_value[2]}", 0, 10, 1)
position = enc.position
if last_position == None or position != last_position:
print(position)
last_position = position
if not enc_btn.value:
sub_menu = not sub_menu
enc.position = 0
time.sleep(0.1)
if not sub_menu:
menu_item = position % 3
else:
colour[menu_item] = position
if enc.position < 0:
position = 0
enc.position = 0
if enc.position > 255:
position = 255
enc.position = 255
neopixel.fill((colour[0],colour[1],colour[2]))
# oled.text(f'Position: {position}', 0, 0, 1)
oled.show()

42
code.py
View File

@ -1,6 +1,16 @@
# 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
import neopixel
@ -25,30 +35,37 @@ enc = rotaryio.IncrementalEncoder(board.D5, board.D4)
enc_btn = digitalio.DigitalInOut(board.D3)
enc_btn.direction = digitalio.Direction.INPUT
# Set strings
SMT1 = "Set"
SMT2 = "Colour :3"
# Start the main loop
last_position = None
colour = [128,128,32]
brightness = 1.0
menu_item = 0
sub_menu = False
while True:
if menu_item == 0:
menu = "[R] G B"
menu = "[R] G B !"
if menu_item == 1:
menu = "R [G] B"
menu = "R [G] B !"
if menu_item == 2:
menu = "R G [B]"
menu = "R G [B] !"
if menu_item == 3:
menu = "R G B [!]"
# Get neopixel colour value
current_r, current_g, current_b = neopixel[0]
# Init the oled
oled.fill(0)
# Draw the menu
oled.text(menu, 0, 0, 1)
oled.text("*" if sub_menu else " ", 64, 0, 1)
oled.text(f"{current_r}:{current_g}:{current_b}", 0, 10, 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)
# Show the oled
oled.show()
@ -69,6 +86,9 @@ while True:
elif menu_item == 2:
if not (current_b + 1) > 255:
current_b += 1
elif menu_item == 3:
if not (brightness + 0.01) >= 1:
brightness += 0.01
# If we went left
elif enc.position < last_position:
@ -86,10 +106,14 @@ while True:
elif menu_item == 2:
if not (current_b - 1) < 0:
current_b -= 1
elif menu_item == 3:
if not (brightness - 0.01) <= 0:
brightness = brightness - 0.01
if not enc_btn.value:
sub_menu = not sub_menu
time.sleep(0.1)
neopixel.fill((current_r, current_g, current_b))
neopixel.brightness = brightness
last_position = enc.position