﻿ Randomizing machine for teachers » Gembcior.pl

# 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: 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.

 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 \$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:

 1234567891011121314151617181920212223242526272829303132 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.

 1234567891011121314151617181920212223 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.

File Size
PCB Termotransfer 16,0kb
PCB – Montaż 27,5kb 