I am writing code for a live car turn signal.
I can make an LED flash, and I can make a polygon change its fill color to simulate a turn signal.
This worked for the led:
def blink_arrow():
leftBlinker.blink(on_time=.7, off_time=.3, n=3)
and this worked for the shape fill:
def blink_arrow(count=0):
global arrow_color
global left_arrow
if arrow_color == "green":
left_arrow = c.create_polygon(50, 100, 150, 75, 150, 125, fill="gray")
elif arrow_color == "gray":
left_arrow = c.create_polygon(50, 100, 150, 75, 150, 125, fill="green")
if count <5:
w.after(300 if left_arrow=="green" else 700, blink_arrow, count+1)
Here is what I tried, but didn't work:
from tkinter import Canvas
from gpiozero import Button, LED
button = Button(23)
leftBlinker = LED(17)
def blink_arrow(count=0):
leftBlinker.blink(on_time=.7, off_time=.3, n=1)
global arrow_color
global left_arrow
if arrow_color == "green":
left_arrow = c.create_polygon(50, 100, 150, 75, 150, 125, fill="gray")
elif arrow_color == "gray":
left_arrow = c.create_polygon(50, 100, 150, 75, 150, 125, fill="green")
if count <5:
w.after(300 if left_arrow=="green" else 700, blink_arrow, count+1)
#Build window, canvas, shape
button.when_pressed = blink_arrow
HERE IS THE NEW CODE ACCORDING TO YOUR SUGGESTION:
def blink_arrow(count=0)
#code for function as written in my first example
pass
def blink_leftLED():
leftBlinker.blink(on_time=.7, off_time=.3, 3)
pass
def left_signal():
l1 = Thread(blink_arrow)
l2 = Thread(blink_leftLED)
l1.start()
l2.start()
left_button.when_pressed = left_signal
Here is the error:
...line 28 in left_signal
l1 = Thread(blink_arrow)
...line reference to threading.py...
assert group is None, "group argument must be none for now"
Please help. :)
I expected the polygon and the LED to "flash" in sync. I can make them blink individually with discreet functions, but not together. When I try to call both in a single function, as above, the light turns on and the fill color changes once.