Restructured and added starter instructions

This commit is contained in:
2024-11-13 23:00:29 +01:00
parent 5c26facc0f
commit 8a17a02ac2
4 changed files with 19 additions and 0 deletions

36
examples/quittable.py Normal file
View File

@@ -0,0 +1,36 @@
from lcdMenu import lcdMenu
from machine import Pin, I2C
from PCF8574T import I2C_LCD
prev_btn = Pin(13, Pin.IN, Pin.PULL_DOWN) # input of the first btn
next_btn = Pin(14, Pin.IN, Pin.PULL_DOWN) # input of the second btn
ok_btn = Pin(15, Pin.IN, Pin.PULL_DOWN) # input of switch
LCD = I2C_LCD(I2C(0, sda=Pin(8), scl=Pin(9), freq=400000),0x27,2, 16)
def first_callback():
print("first_callback() called!")
def second_cb():
print("second_cb() called")
def third_cb():
print("third_cb() called")
return True
button_mappings = {"prev_btn":prev_btn, "next_btn": next_btn, "ok_btn": ok_btn}
submenu = lcdMenu(LCD, button_mappings, scroll_direction=True, cycle=False, hide_menu_name=False, name="Submenu!")
# the submenu.stop callback is a special callback specifically designed for use cases where the lcdMenu ist started with run()
# submenu.stop breaks an infinite loop inside the run() method, essentially quitting the run() method and giving back flow to the caller context
# so we can utilize this for us to quit a submenu (or a "main" menu if you want to, of course!)
submenuItems = [("first item", first_callback),
("second item", second_cb),
("third item", third_cb),
("back", submenu.stop)]
submenu.setup(submenuItems)
mainmenu = lcdMenu(LCD, button_mappings, scroll_direction=False, cycle=True, hide_menu_name=False, name="Main menu!")
mainmenu.setup([("Sub menu",submenu.run)])
mainmenu.run()

27
examples/simple.py Normal file
View File

@@ -0,0 +1,27 @@
from lcdMenu import lcdMenu
from machine import Pin, I2C
from PCF8574T import I2C_LCD
prev_btn = Pin(13, Pin.IN, Pin.PULL_DOWN) # input of the first btn
next_btn = Pin(14, Pin.IN, Pin.PULL_DOWN) # input of the second btn
ok_btn = Pin(15, Pin.IN, Pin.PULL_DOWN) # input of switch
LCD = I2C_LCD(I2C(0, sda=Pin(8), scl=Pin(9), freq=400000),0x27,2, 16)
def first_callback():
print("first_callback() called!")
def second_cb():
print("second_cb() called")
def third_cb():
print("third_cb() called")
return True
menuItems = [("first item", first_callback),
("second item", second_cb),
("third item", third_cb)]
menu = lcdMenu(LCD, {"prev_btn":prev_btn, "next_btn": next_btn, "ok_btn": ok_btn}, scroll_direction=False, cycle=False, hide_menu_name=True, name="Fullscreen!")
menu.setup(menuItems)
menu.run()

32
examples/submenu.py Normal file
View File

@@ -0,0 +1,32 @@
from lcdMenu import lcdMenu
from machine import Pin, I2C
from PCF8574T import I2C_LCD
prev_btn = Pin(13, Pin.IN, Pin.PULL_DOWN) # input of the first btn
next_btn = Pin(14, Pin.IN, Pin.PULL_DOWN) # input of the second btn
ok_btn = Pin(15, Pin.IN, Pin.PULL_DOWN) # input of switch
LCD = I2C_LCD(I2C(0, sda=Pin(8), scl=Pin(9), freq=400000),0x27,2, 16)
def first_callback():
print("first_callback() called!")
def second_cb():
print("second_cb() called")
def third_cb():
print("third_cb() called")
return True
menuItems = [("first item", first_callback),
("second item", second_cb),
("third item", third_cb)]
button_mappings = {"prev_btn":prev_btn, "next_btn": next_btn, "ok_btn": ok_btn}
submenu = lcdMenu(LCD, button_mappings, scroll_direction=True, cycle=False, hide_menu_name=False, name="Submenu!")
submenu.setup(menuItems)
mainmenu = lcdMenu(LCD, button_mappings, scroll_direction=False, cycle=True, hide_menu_name=False, name="Main menu!")
mainmenu.setup([("Sub menu",submenu.run)])
mainmenu.run()