#Sounds like you might like this Learn

1 messages · Page 1 of 1 (latest)

dense sky
#

I have read that a bit.

the on works, do you write an off statement as an "else"

severe dagger
#

not sure what you mean by "off statement"

#

the if-statement there is just acting as a metronome. it triggers ever 1.5 seconds. You can do whatever you like inside that. If there is a value you need to toggle then that goes in there. For instance, if you wanted to switch between two LED colors, that might look like:

last_led_time = time.monotonic()
led_color1 = 0xff00ff
led_color2 = 0x00cc33
led_color = led_color1  # saves what color we're currently at
while True:
  if time.monotonic() - last_blink_time > 1.5:
    last_led_time = time.monotonic()
    if led_color == led_color1:
      led_color = led_color2 # toggle to color 2
    else:
      led_color = led_color1 # toggle to color 1
    pixels.fill( led_color )
dense sky
#

and that would toggle. back and fourth at 1.5?

severe dagger
#

should do yeah

dense sky
#

interesting let me try

#

its just flashing at un controlled amount

#

hmm

#

pixels.brightness = .05
sleepytime = 5
displaytime = 5
last_led_time = time.monotonic()
screen = pixel_test

while True:
now = time.monotonic()
for color in BLINK_MAP.keys(): # pylint: disable=consider-iterating-dictionary
# Is LED currently OFF?
if pixels[BLINK_MAP[color]["INDEX"]] == (0, 0, 0):
# Is it time to turn ON?
if now >= BLINK_MAP[color]["PREV_TIME"] + BLINK_MAP[color]["OFF"]:
pixels[BLINK_MAP[color]["INDEX"]] = BLINK_MAP[color]["COLOR"]
BLINK_MAP[color]["PREV_TIME"] = now
else: # LED is ON:
# Is it time to turn OFF?
if now >= BLINK_MAP[color]["PREV_TIME"] + BLINK_MAP[color]["ON"]:
pixels[BLINK_MAP[color]["INDEX"]] = (0, 0, 0)
BLINK_MAP[color]["PREV_TIME"] = now
if time.monotonic() - last_led_time > 2:
last_led_time = time.monotonic()
if screen == pixel_test():
display.fill(0)
pixel_test()
screen = line_test() # toggle to color 2
else:
line_test()
screen = pixel_test()
# toggle to color 1

#

so i am just trying to cycle through some screen test animations right now as a test. because i wnat the screen to say stuff and the time to not effect something else. in this case the Blink map which is a 10 strip neo pixel setup all flashing at different times.

severe dagger
#

Sorry been traveling for the holidays. your for-loop will be executed every time through the while-loop (i.e. as fast as possible). The part that will be executed ever 2 seconds is your if screen == pixel_test() bit. But I'm not sure what pixel_test is since you refer to it both as a variable screen = pixel_test and as a function if screen == pixel_test()

dense sky
#

Hope you had a good time and thanks for getting back to me. So pixel_test is an screen animation setup in a definition:

#

So I made screen.test() and the other tests as functions.

I think my thing with time.monotonic is that everyone using it is using it with an if statement about something being on or off or a bool

How do i set set the screen animation as a bool? you know? like how can it know what animation or action is happening so i can trigger the next animation or action. I think maybe that is the issue. how can i set anything i do to a variable of "has this happened"