Randomizing machine for teachers

14th October is Teacher’s Day in Poland. That’s why I created this nifty gadget which I’m sure will be helpful for every teacher. Let’s think for a moment about difficulties which teachers are facing every day. They must choose one volunteer out of thirty-something students who will come to the blackboard. And here’s where my thingy comes in handy. Thanks to my device teachers won’t have to choose anyone but will rely on the power of random numbers!

How does it work?

This toy is being steered by ATmega8 microcontroller. C1 and C2 capacitors are filtering voltage for the microcontroller. An LCD display has been connected to microcontroller ports through resistors which are limiting the voltage. The whole device needs 5V power source, in my case power is provided by 3xLR03 batteries. Here’s the schematic diagram:

Maszynka copy

The microcontroller program code which is responsible for picking up a random number is a little bit more complicated. The code was written in Bascom AVR programming language.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
$regfile = "m8def.dat" 'ATmega8
$crystal = 1000000

Config Portc = B1110011
Portc = B0111100
Config Portb = B1011110
Portb = B11111111
Config Portd = Output
Portd = B11111111

Config Timer0 = Timer , Prescale = 1
Config Timer2 = Timer , Prescale = 8
On Timer0 Przerwanie
On Timer2 Przerwanie2
Enable Interrupts

Dim Numer As Byte
Dim Numer2 As Byte
Dim Licznik As Byte
Dim Waz As Byte
Dim Stan_portu As Byte
Dim Stan_portu2 As Byte
Dim A As Byte
Load Timer0 , 100
Load Timer2 , 100
Waz = 0

Portc.5 = 1
Portc.4 = 1
Portd.0 = 0 'Animacja startowa
Waitms 300
Portd.1 = 0
Waitms 300
Portd.2 = 0
Waitms 300
Portd.3 = 0
Waitms 300
Portd.4 = 0
Waitms 300
Portd.5 = 0
Waitms 100
For A = 1 To 4
Portd = B11000000
Waitms 250
Portd = B11111111
Waitms 250
Next A

Do
Portc.5 = 1
Portc.4 = 1

If Pinb.6 = 0 Then 'Losowanie
Portd = 255
Enable Timer0
Enable Timer2
Do
If Pinb.6 = 1 Then
Disable Timer0
Disable Timer2
Exit Do
End If
Loop
Portd = 255
Waitms 100
Stan_portu = Lookup(numer , Ledlcd)
Stan_portu2 = Lookup(numer2 , Ledlcd2)
Do
Portc.5 = 1
Portc.4 = 0
Portd = Stan_portu
Waitms 10
Portc.5 = 0
Portc.4 = 1
Portd = Stan_portu2
Waitms 10
If Pinb.6 = 0 Then
Exit Do
Elseif Pinb.0 = 0 Then
Exit Do
End If
Loop
End If

Portc.5 = 1
Portc.4 = 1

If Pinb.0 = 0 Then 'Funkcja dodatkowa
Portd = 255
Enable Timer0
Enable Timer2
Do
If Pinb.0 = 1 Then
Disable Timer0
Disable Timer2
Exit Do
End If
Loop
Portd = 255
Waitms 100
Do
Portc.5 = 1
Portc.4 = 0
Portd = B11111001
Waitms 10
Portc.5 = 0
Portc.4 = 1
Portd = B11111001
Waitms 10
If Pinb.0 = 0 Then
Exit Do
Elseif Pinb.6 = 0 Then
Exit Do
End If
Loop
End If
Loop

Przerwanie: 'Przerwanie
Load Timer0 , 100
Incr Numer
If Numer = 11 Then Numer = 0
Incr Licznik
If Licznik = 255 Then 'Część odpowiedzialna za wyświetlanie węża podczas losowania
Licznik = 0
Incr Waz
If Waz = 6 Then
Portd.5 = 1
Waz = 0
End If
Portd.waz = 0
Waz = Waz - 1
Portd.waz = 1
Waz = Waz + 1
End If
Return

Przerwanie2:
Load Timer2 , 100
Incr Numer2
If Numer2 = 4 Then Numer2 = 0

Return

Ledlcd:
Data B11000000 , B11111001 , B10100100 , B10110000 , B10011001 , B10010010 , B10010010 , B10000010 , B11111000 , B10000000 , B10010000 ,
Ledlcd2:
Data B11000000 , B11111001 , B10100100 , B10110000 ,

I won’t be describing the whole logic of the program, but I’ll focus on the most important bits. First of them is located below:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
Do
If Pinb.6 = 0 Then
Portd = 255
Enable Timer0
Enable Timer2
Do
If Pinb.6 = 1 Then
Disable Timer0
Disable Timer2
Exit Do
End If
Loop
Portd = 255
Waitms 100
Stan_portu = Lookup(numer , Ledlcd)
Stan_portu2 = Lookup(numer2 , Ledlcd2)
Do
Portc.5 = 1
Portc.4 = 0
Portd = Stan_portu
Waitms 10
Portc.5 = 0
Portc.4 = 1
Portd = Stan_portu2
Waitms 10
If Pinb.6 = 0 Then
Exit Do
Elseif Pinb.0 = 0 Then
Exit Do
End If
Loop
End If

It is responsible for steering the button. In the moment when the button S1 is pressed b.6 Port is connected to the ground. Then, the LCD display is cleared and it unlocks the disruption to Timer0 and Timer2 in which the numbers are being drawn. After that the program goes into the endless loop which can be broken only when the S1 button is released. Before exiting the loop Timer0 and Timer2 disruption is being blocked. After the program leaves the loop, the display is cleared again, then the chosen number is being displayed. Another important part of the program is the body of the disruption.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
Przerwanie1:
Load Timer0 , 100
Incr Numer
If Numer = 11 Then Numer = 0
Incr Licznik
If Licznik = 255 Then
Licznik = 0
Incr Waz
If Waz = 6 Then
Portd.5 = 1
Waz = 0
End If
Portd.waz = 0
Waz = Waz - 1
Portd.waz = 1
Waz = Waz + 1
End If
Return

Przerwanie2:
Load Timer2 , 100
Incr Numer2
If Numer2 = 4 Then Numer2 = 0

Disruption1 is responsible for drawing random ones and Disruption2 is responsible for picking a random tens. In the beginning it is loading a new value which equals 100 into the Timer counter. Then there’s an incrementation of Numer variable. The next instruction is preventing the random number to leave a defined spectrum and in case of leaving the defined range it sets the value for 0. The remaining instructions are responsible for additional light effect on the display while the random number is being drawn.

I also designed a PCB board:

In the original version of the PCB board I discovered a small mistake which wasn’t detected at the design phase, but fortunately I was able to fix it quickly, so there’s nothing to worry about.

The whole device was fitted into the plastic case model Z-76, which I bought on allegro (Polish ebay). The screen cover was made out of jewel CD case, on which I applied window tint foil. The program is drawing numbers from 0 to 39 spectrum, but after a slight modification to the source code you can change it up to 99. The toy has one more additional feature, which was designed especially for my teacher, for whom this whatchamacallit was given. After the S2 button is pressed, the thingy displays the number of my teacher’s “favorite“ student. The number the S2 button calls can also be easily changed.

List of elements:

8x 470 Ohm
1x 100nF
1x 10uF
2x Tact Switch
1x ATmega8
1x LCD display of any kind, I used FYD-5621FE

The device was given as a gift from the whole class and everyone liked it, especially my teacher. Below you can find a gallery and a short film presenting how it works.

Download:

File Size
PCB Termotransfer 16,0kb
PCB – Montaż 27,5kb
Program-wsad 1,99kb
Randomizing machine for teachers
Bądź pierwszy i oceń!

No Comments

Leave a Reply

*

*

Ile jest * Time limit is exhausted. Please reload CAPTCHA.

banner

This site uses cookies to store information on your computer. Click for more details

Our site uses cookies to personalise site content and advertisement, to offer social network functions and to analyse traffic on our website. Information we gather about using our website are shared with our social media, advertisement and analytical partners. You can find more info on How Google uses data when you use our partners' sites or apps.

Close