User manual

87
10.3 Setting the flashing rate
In a third step, the dialog box is expanded again. The user can now adjust with a slider, the blinking speed.
Fig. 10.6: Three LED patterns to choose from
and the customizable flashing rate.
Use of the sliders
Slide controls provide a very intuitive way to enter numerical values within a defined range. We are
spared the plausibility query, which verifies whether the user has entered a value that the programme is
able to implement, because slider don’t allow values that are lying outside the specified range. Configure
the slider always in a way, that the values are comprehensible for the user. It makes no sense to set up
values in the millions. If the absolute numerical value itself is not an issue, give the user an easy a scale
ranging from 1 to 10 or 100 and convert the value in the programme accordingly. The values should
increase from left to right, if it were the other way around, most users would consider that odd. Also
always give a meaningful value, which wil be applied in case the user does not modify the slider.
The programme ledtk03.py is almost similar to the previous example, only the regulation of speed is
added.
import RPi.GPIO as GPIO
import time
from Tkinter import *
GPIO.setmode(GPIO.BCM); LED = [4,18,23,24]
for i in LED:
GPIO.setup(i, GPIO.OUT, initial=0)
w = 5
pattern = [
("Chasing to the left",1), ("Flashing",2), ("Chasing to the right”,3)
]
root = Tk(); root.title("LED"); v = IntVar(); v.set(1); g = IntVar(); g.set(5)
def LedOn():
e = v.get()
t = 1.0/g.get()
if e == 1:
for i in range(w):
for j in range(4):