Added another demo, this one showing off the lcd driver functionality

This commit is contained in:
BlueFox 2024-11-16 15:09:04 +01:00
parent ddde9480ff
commit 5ce8e592c3
Signed by: BlueFox
GPG Key ID: 327233DA85435270
2 changed files with 84 additions and 14 deletions

62
lcd_driver_demo.py Normal file
View File

@ -0,0 +1,62 @@
"""
An example "program" which can be used with the lcdMenu library on a 2x16 display (with some tweaks also on 4x20 displays)
Copyright (C) 2024 Benjamin Burkhardt <bluefox@privacynerd.de>
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
"""
@ Feature: Demonstrates the lcd driver's functionality
"""
from time import sleep
from utils import log
# lcd is an object of the I2C_LCD class (https://git.privacynerd.de/BlueFox/micropython-libraries/src/branch/main/PCF8574T)
def run(lcd):
# Show off basic functionality of the lcd driver
log(2, "Running the lcd driver demo")
lcd.putstr("Driver demo".center(16))
sleep(1)
lcd.clear()
lcd.putstr("Lorem ipsum dolor sit amet")
sleep(1)
lcd.show_cursor()
sleep(1)
lcd.hide_cursor()
sleep(1)
lcd.blink_cursor_on()
sleep(1)
lcd.blink_cursor_off()
sleep(1)
lcd.backlight_off()
sleep(1)
lcd.backlight_on()
sleep(1)
lcd.display_off()
sleep(1)
lcd.display_on()
sleep(1)
lcd.clear()
sleep(1)
s = ""
for x in range(32, 127):
s += chr(x)
while len(s) > 0:
lcd.clear()
lcd.move_to(0,0)
lcd.putstr(s[:32])
s = s[32:]
sleep(1)
lcd.clear()
return True
if __name__ == "__main__":
import utils
run(utils.Config().LCD)

36
main.py
View File

@ -81,17 +81,6 @@ def timer():
del timer_menu, timer_programs
collect()
return True # disable the "Quitting" message from lcdMenu
def lcd_big_hello():
import lcd_big_hello as lbh
lbh.run(config.LCD)
del lbh
collect()
return True
def input_tests():
import input_tests as input_tests
input_tests.run(serial_output=False)
collect()
return True
def settings():
settings_menu = lcdMenu(config.LCD, btn_mapping, scroll_direction=True, cycle=True, hide_menu_name=False, name="SETTINGS")
def swap_welcome():
@ -250,7 +239,7 @@ def settings():
return True
current_level -= 1
if current_level < 1: current_level = 3
if current_level < 0: current_level = 2
config.LCD.putstr(f"{'Log level'.center(16)}\nv {str(current_level).center(12)} ^")
if btn_right.value() == 1:
sleep(0.1)
@ -263,7 +252,7 @@ def settings():
pass
return True
current_level += 1
if current_level > 3: current_level = 1
if current_level > 2: current_level = 0
config.LCD.putstr(f"{'Log level'.center(16)}\nv {str(current_level).center(12)} ^")
def reset(): # reset all user-settable configuration to the default values
@ -307,8 +296,27 @@ def settings():
collect()
return True
def run_demo_menu():
def lcd_driver_demo():
import lcd_driver_demo as ldd
ldd.run(config.LCD)
del ldd
collect()
return True
def lcd_big_hello():
import lcd_big_hello as lbh
lbh.run(config.LCD)
del lbh
collect()
return True
def input_tests():
import input_tests as input_tests
input_tests.run(serial_output=False)
del input_tests
collect()
return True
demo_menu = lcdMenu(config.LCD, btn_mapping, scroll_direction=True, cycle=True, hide_menu_name=False, name="DEMOS")
demo_programs = [("LCD Demo", lcd_big_hello),
demo_programs = [("LCD Demo", lcd_driver_demo),
("Hello world", lcd_big_hello),
("Input tests", input_tests),
("Exit", demo_menu.stop)]
demo_menu.setup(demo_programs) # give it the callback list