液晶显示器的micropython菜单
upymenu的Python项目详细描述
乌普梅努
uPyMenu是一个用于LCD显示的micropython菜单实现。来自Arduino的经验,我曾与LiquidCrystal和{a2}一起使用,但它们没有提供python实现。所以我想我可以自己做一个。
发展
当前的开发是基于何时我必须在我想做的时候工作。但你可以自由的添加你的功能。如果您发现任何错误或对功能有建议,请打开一个问题(或者,如果您自己创建了该功能,则请求拉入!)。
托多
- 向菜单中的回调操作添加参数
使用
下面的示例呈现一个菜单,其中包含一个子菜单和附加了回调的操作,可以用来运行自己的函数。它需要一个依赖项,那就是^{
frommachineimportPin,I2C# Basics for creating an LCD interfacefromesp8266_i2c_lcdimportI2cLcd# Example LCD interface usedfromupymenuimportMenu,MenuAction,MenuNoopdefaction_callback():print("callback action chosen")submenu=Menu("Submenu")submenu_action_1=MenuAction("Submenu Action",callback=action_callback)submenu_action_2=MenuAction("Submenu Action 1",callback=action_callback)submenu.add_option(submenu_action_1)submenu.add_option(submenu_action_2)menu_action=MenuAction("Action",callback=action_callback)menu=Menu("Main Menu")menu.add_option(submenu)menu.add_option(menu_action)menu.add_option(MenuNoop("Nothing here"))# Example config for LCD via i2c, you will need this # for the menu to function, the screen size is required# to render the menu correctly on the screen.i2c=I2C(scl=Pin(5),sda=Pin(4),freq=400000)lcd=I2cLcd(i2c,0x3F,4,20)current_menu=menu.start(lcd)# Starts the menu on the LCDmenu.focus_next()# Focus on the next item in the menu menu.focus_prev()# Focus on the previous item in the menu # Choose the focused item, if it's and action execute # the callback, or if it is a menu, render that menu.menu=menu.choose()# If it's a submenu, you can use the parent() function# to navigate back up to the tree.menu=menu.parent()
测试
如果您有一个micropython
端口在本地运行,您可以用它来运行测试套件,即:micropython tests.py
。这与我目前对micropython的了解非常接近。如有任何改进的建议和建议,我们将不胜感激!
- 项目
标签: