Hey!
First of all, I am having a ton of fun playing around with the Pi Zero and Scroll pHAT – thanks for putting this little LED wonder out there! But as this is my first time programming since I was a nipper, I’m having a little bit of trouble getting over a certain hurdle.
I’m familiar with while
loops to scroll the string in the buffer across the LEDs, but I’m unsure how to change what’s in the buffer based on the user’s input. Also I want to use an initial message as a prompt, a bit like a print("context")
would give the user context. Can anyone help?
import time
import scrollphat
# I'm clearing anything in the buffer on execution
scrollphat.clear()
scrollphat.set_brightness(7)
scrollphat.set_rotate(True)
# This is the initial prompt, asking user for input
def greet_me():
while True:
scrollphat.write_string("Say hello to me", 11) # Write message to buffer
scrollphat.scroll() # Move buffer left by one column
time.sleep(0.1) # Sleep 0.1 seconds, continue loop
# This is the response based on user input: clear buffer then respond
def say_thanks():
scrollphat.clear()
while True:
scrollphat.write_string("Hello you!", 11)
scrollphat.scroll()
time.sleep(0.1)
greeting = ""
while greeting != "hello":
greet_me()
What I want to do next is run through the say_thanks()
loop when greeting == "hello"
. I need to set greeting = input()
at some point but I’m not sure where. What do you reckon, oh wise ones?
Thanks in advance for any help!