Lessons 61–62 · 2 lessons · N. I. Taylaqov (general editor), A. B. Akhmedov, M. D. Pardayeva, A. A. Abdug‘aniyev, U. M. Mirsanov. Informatics and Information Technologies, Grade 10, 1st edition. “Extremum-Press”, Tashkent, 2017
62
Practical lesson
Textbook: p. 143
GoalCreates applications with a Timer: a clock, a stopwatch and a traffic light; controls the state with the interval, a counter and mod.
New words
stopwatch: a counter of elapsed time · sekundomercounter: a variable that grows by 1 at each timer event · hisoblagichmod: the remainder of a division, used for repeating cycles · modcycle time: the time after which a pattern repeats · sikl vaqti
Explanation
In the practical lesson three applications are created. 1) “Stopwatch”: Interval = 100 (a tenth of a second). Global t: Integer; in the Timer t := t + 1; Label1.Caption := IntToStr(t div 10) + '.' + IntToStr(t mod 10); – for example t = 125 gives 12.5 seconds. Let the Start/Stop button be Timer1.Enabled := not Timer1.Enabled; 2) “Traffic light”: Interval = 1000, global i: Integer; in the Timer i := i + 1; k := i mod 14; – at k = 0…5 red (6 s), at k = 6 yellow (1 s), at k = 7…13 green (7 s); the lights are drawn on an Image with Brush.Color := clRed and Ellipse. 3) “Clock”: a Label with time and date. Important: do not create colour changes that flash more than three times a second on the screen, because this can harm some people; treat the traffic light only as a learning model, on a real road you must obey the signals.
Worked examples
Stopwatch: at t = 125, t div 10 = 12 and t mod 10 = 5: the text is 12.5. At t = 60 it is 6.0. 1 minute = 60 s = 600 events of 100 ms.
The traffic-light cycle is 6+1+7 = 14 seconds. At i = 13, k = 13 mod 14 = 13 – green; at i = 20, k = 6 – yellow; at i = 30, k = 2 – red. The red light stays on for 6 seconds because k = 0, 1, 2, 3, 4, 5 – six events.
Class activity
“The light table”: a pair makes a 25-second table: it writes in advance which light is on each second (k = i mod 14) and checks it with the application.
Practice
1
With Interval = 100, how many OnTimer events happen in 1 minute?
600
2
If t = 87, what does the stopwatch show (t div 10 and t mod 10)?
8.7
3
What is the traffic-light state at i = 40 (k = i mod 14; 0–5 red, 6 yellow, 7–13 green)?
k = 12: green
4
Why should fast flashing colours be avoided?
Flashing more than three times a second can harm some people.