print("Hello, Pi Pico!")
# ToDo
# Thread Control:
# Get state of the stepper motor driver
# Stepper controller
# Thread GUI
# Get push button state
# Get turn count of rotary encoder
# Update screen
# Menu
# Calibrate slider length (drive until overload and return)
# Start new sequence
# Shots per length
# Number of lengths
import board
import displayio
import terminalio
import busio
from adafruit_display_text import label
import adafruit_displayio_ssd1306
import time
import time
displayio.release_displays()
# Initialize I2C bus and the display
i2c = busio.I2C(scl=board.GP21, sda=board.GP20)
display_bus = displayio.I2CDisplay(i2c, device_address=0x3C)
WIDTH = 128
HEIGHT = 64
BORDER = 5
# Define menu items
menu_items = ["1. NEW RUN", "2. CAL", "3. STATS"]
menu_item_selected = 0
display = adafruit_displayio_ssd1306.SSD1306(display_bus, width=WIDTH, height=HEIGHT)
# Make the display context
splash = displayio.Group()
display.show(splash)
color_bitmap = displayio.Bitmap(WIDTH, HEIGHT, 1)
color_palette = displayio.Palette(1)
color_palette[0] = 0xFFFFFF # White
bg_sprite = displayio.TileGrid(color_bitmap, pixel_shader=color_palette, x=0, y=0)
splash.append(bg_sprite)
# Draw a smaller inner rectangle
inner_bitmap = displayio.Bitmap(WIDTH - BORDER * 2, HEIGHT - BORDER * 2, 1)
inner_palette = displayio.Palette(1)
inner_palette[0] = 0x000000 # Black
inner_sprite = displayio.TileGrid(
inner_bitmap, pixel_shader=inner_palette, x=BORDER, y=BORDER
)
splash.append(inner_sprite)
# Function to display menu
def display_menu():
global menu_item_selected
while True:
# Clear display
display.clear()
# Print menu items
for i, item in enumerate(menu_items):
if i == menu_item_selected:
oled.text("> " + item, 0, i * 10)
else:
oled.text(item, 0, i * 10)
# Show display
oled.show()
# Wait for button input
# (Assuming buttons are connected to pins 12, 13, and 14)
while not board.BUTTON_A.value and not board.BUTTON_B.value and not board.BUTTON_C.value:
time.sleep(0.1)
if not board.BUTTON_A.value:
menu_item_selected = 0
elif not board.BUTTON_B.value:
menu_item_selected = 1
elif not board.BUTTON_C.value:
menu_item_selected = 2
# Wait for button release
while not board.BUTTON_A.value and not board.BUTTON_B.value and not board.BUTTON_C.value:
time.sleep(0.1)
# Perform action based on selected menu item
if menu_item_selected == 0:
# Perform action for "1. NEW RUN" menu item
pass
elif menu_item_selected == 1:
# Perform action for "2. CAL" menu item
pass
elif menu_item_selected == 2:
# Perform action for "3. STATS" menu item
pass
# Start menu loop
display_menu()
print("Done! Press Ctrl+C to get into the REPL")
while True:
time.sleep(1)