Many small changes to WelcomeScreen.py

Changed a parameter name from loops to cycles (for clarity); 
Improved the fading down animation in the end of the startup screen; 
Made the class more flexible (should now work on 4x20 LCDs also);
This commit is contained in:
BlueFox 2024-10-28 10:27:00 +00:00
parent 6e74bf3be0
commit 412ea72867

View File

@ -18,34 +18,34 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
import time import time
"""
WelcomeScreen:
provide a simple welcome/startup screen
"""
class WelcomeScreen: class WelcomeScreen:
def __init__(self, lcd): def __init__(self, lcd):
self.lcd = lcd self.lcd = lcd
def show_welcome(self, loops=1): # loops says how often the Starting text goes through def show(self, cycles=1): # loops says how often the Starting text goes through
if loops < 1: loops = 1 if cycles < 1: cycles = 1
padding = " " # 16 spaces padding = " " * self.lcd.num_columns # as much spaces as padding as one display line is long
started_str = " Started! " starting_str = "Starting..."
started_str = "Started!".center(self.lcd.num_columns)
for i in range(loops): for i in range(cycles):
line1 = padding + "Starting..." + padding line1 = padding + starting_str + padding
line2 = " the Program " line2 = "The Program!".center(self.lcd.num_columns)
for i in range(32): for i in range(self.lcd.num_columns + len(starting_str)):
self.lcd.putstr(line1[0:16]) self.lcd.putstr(line1[0:self.lcd.num_columns])
self.lcd.move_to(0,1) self.lcd.move_to(0,1)
self.lcd.putstr(line2[0:16]) self.lcd.putstr(line2[0:self.lcd.num_columns])
line1 = line1[1:] line1 = line1[1:]
self.lcd.move_to(0,0) self.lcd.move_to(0,0)
self.lcd.putstr(started_str) self.lcd.putstr(started_str)
# now fade down # now fade down
time.sleep(2) time.sleep(1)
self.lcd.move_to(0,0) self.lcd.move_to(0,0)
self.lcd.putstr(padding + started_str) self.lcd.putstr(padding + started_str)
time.sleep(0.1) time.sleep(0.1)
self.lcd.clear() self.lcd.clear()
time.sleep(0.3)