I have been using my lack of programming knowledge to write an app for a weather sensor that doubles as a flashlight and allow the screen t ogo dark. The problem is that when it is scrolling data, it will not interrupt the scrolling to switch modes. Is there a way to cause a joystick action to interrupt the current action and switch to the new one?
It also appears that the scroll repeats at least twice every time it is activated, which is not much of a problem because when it is scrolling, I want it to ocntinue until another action is selected.
It also appears that the scroll repeats at least twice every time it is activated, which is not much of a problem because when it is scrolling, I want it to ocntinue until another action is selected.
Code:
# Import required librariesfrom sense_hat import SenseHatimport timefrom random import randintsense = SenseHat()sense.clear()# Set constantsred = (255, 0, 0)green = (0, 255, 0)blue = (0, 0, 255)white = (255, 255, 255)black = (0, 0, 0)forecolor = blackbackcolor = black# Define functionsdef flashlight(): sense.clear(white)def darkmode(): sense.clear(black)def normal(): # Numeric modifications are to calibrate to data received from wunderground.com temp = (sense.get_temperature() * 1.8) + 32 -16.57289390563966 humidity = sense.get_humidity() + 33 pressure = sense.get_pressure() * 0.02953 +0.82704619140625 # Round the values to one decimal place temp = round(temp, 1) pressure = round(pressure, 1) humidity = round(humidity, 1) # Create the message # str() converts the value to a string so it can be concatenated message = "Temp: " + str(temp) + " Hg: " + str(pressure) + " Hum: " + str(humidity)# Normal temperature backcolor = green forecolor = white# Consider a sweatshirt if temp < 65: backcolor = blue# Remove any excess layers of clothing if temp > 80: backcolor = red sense.show_message(message, scroll_speed=0.05, text_colour=forecolor, back_colour=backcolor)# Begin appwhile True: sense.stick.direction_up = flashlight sense.stick.direction_down = darkmode sense.stick.direction_left = normal sense.stick.direction_right = normal
Statistics: Posted by Antimidas763 — Mon May 27, 2024 9:04 pm — Replies 0 — Views 6