Reaction Timer part 2

Last time they made a good start on the software. In the final lesson they'll finish the software, build the hardware and see who's got the fastest reactions!

Learning objectives

Students will learn:

Resources

Lesson Plan

Setup the Pi : 5 minutes

Make a note of the best time. This will be useful to share with other teachers, and with future students!

Finish writing the code : 20 minutes

Reference code is included here.

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
#import the libraries
import time
import random
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)

button_pin = 8
led_pin = 10

#set the button pin to be True to start,
#when we press the button, the pin will change to False.
GPIO.setup(button_pin,GPIO.IN, pull_up_down=GPIO.PUD_UP)

#set the led pin to be an output
GPIO.setup(led_pin, GPIO.OUT)
GPIO.output(led_pin,False)

#how long should we wait before turning on the led
sleep_time = random.randint(3,10)

#wait for our random time
time.sleep(sleep_time)

#turn on the led and store the current time in a variable
GPIO.output(led_pin, True)
start_time = time.time()

#wait for the button to be pressed...
while True:
    if GPIO.input(button_pin) == False:
        print("stopped!")
        #finish the while loop
        break

#work out how long they took:
reaction_time = time.time() - start_time
print("you got" + str(reaction_time) + "seconds")

Build reaction timer hardware : 15 minutes

Circuit diagrams haven't been included in the final handout as students have already seen and have copies of a button and LED circuit. If they get stuck, you can show them your copy:

 Reaction Timer

Extension activity

They don't get a great representation of reaction time without making multiple measurements (just like in science). Find a way to repeat the test 3 times and make an average before printing a final score.

Who's the fastest? : 10 minutes

Now it's time to run the competition! To save time, they'll play a 'sudden death' tournament. If a student loses then they get knocked out.

Ask all pairs to test each other. The winners then play against each other. A class of 30 should only need 5 tests to find the overall winner.

You can ask at the end how to make the competition fairer, as the ways that the students come up with will probably be fairly straight forward to add to our program. For example taking 3 scores and making an average gets rid of the bad luck element.

Pack away : 5 minutes

Pack away the Pi.

Homework

Continue from the project started in lesson 4. Students should now have a project description, a circuit diagram and some comments and Python code. The final homework is to write a short presentation on their project.

They should include:

If you want to do another Pi project, you could ask the students to present their work and use the most voted project as the starting point.

Outcome

All students:

Most students:

Some students: