User manual
88
GPIO.output(LED[j], True); time.sleep(t)
GPIO.output(LED[j], False)
elif e == 2:
for i in range(w):
for j in range(4):
GPIO.output(LED[j], True)
time.sleep(t)
for j in range(4):
GPIO.output(LED[j], False)
time.sleep(t)
else:
for i in range(w):
for j in range(4):
GPIO.output(LED[3-j], True); time.sleep(t)
GPIO.output(LED[3-j], False)
Label(root,
text=”Please click a button to start the chaser
").pack()
for txt, m in pattern:
Radiobutton(root, text = txt, variable = v, value = m).pack(anchor=W)
Label(root, text=”Speed").pack()
Scale(root, orient=HORIZONTAL, from_ = 1, to = 10, variable = g).pack()
Button(root, text="Start", command=LedOn).pack(side=LEFT)
root.mainloop()
GPIO.cleanup()
10.3.1 How does it work?
The initialization of the libraries and GPIO ports and the definition of the list for the three flashing patterns
correspond to the previous programme. The determination of the variable
t for the flashing time is dropped,
because the slider will read it later.
g = IntVar(); g.set(5) In addition to the Tk variables v,
i
where the selected flashing pattern is stored,
another integer variable
g is defined for speed. The given start value of 5 corresponds to the mean value of
the slider.
def LedOn():
e = v.get(); t = 1.0/g.get()
The function that lets the LEDs flashing also corresponds to the previous example, yet there is one difference.
The variable
t for the duration of flashing is calculated from the value of the slider g.
Because a user intuitively links faster flashing to higher speed, the sliders will deliver higher values to the
right. However, in the programme a shorter waiting time is needed for higher speed, therefore a smaller
value is required. This is achieved by a reciprocal calculation that calculates based on the slider’s values
1 to
10 the values 1.0 to 0.1 for the variable t. 1.0 must stand in the formula and not 1, so that the result will
be a floating point number and not an integer.