From 5ce8e592c326900747dc9a7a3e0d1505cb194a84 Mon Sep 17 00:00:00 2001 From: BlueFox Date: Sat, 16 Nov 2024 15:09:04 +0100 Subject: [PATCH] Added another demo, this one showing off the lcd driver functionality --- lcd_driver_demo.py | 62 ++++++++++++++++++++++++++++++++++++++++++++++ main.py | 36 ++++++++++++++++----------- 2 files changed, 84 insertions(+), 14 deletions(-) create mode 100644 lcd_driver_demo.py diff --git a/lcd_driver_demo.py b/lcd_driver_demo.py new file mode 100644 index 0000000..e6981fb --- /dev/null +++ b/lcd_driver_demo.py @@ -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 + +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 . +""" + + +""" +@ 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) \ No newline at end of file diff --git a/main.py b/main.py index 5efe8c6..0a7a5f9 100644 --- a/main.py +++ b/main.py @@ -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