Final Product

After working on series of codes I have finally finished making it. I have made the code relatively short and simple in order for teachers or people to use it with only the requirement of knowing how to change numbers in the code needed. The code simply tracks separate Id cards(students) and tracks their number of laps and the time difference between them every time they pass the sensor. For example, Id number 556 runs past the sensor and the code will write down how many laps he has down and the number of seconds it took for him to reach the sensor. However, there are some problems with the code as it is. Due to lack of time I haven’t been able to optimize the code for huge classes, that require some more advanced organization of times and students in order to make it more user-friendly. So currently the code is better for smaller groups of runners or a single runner who wish to track the number of laps they can run and how long it takes for them to finish a lap.

1. Tracks number of laps and time of each lap for a runner

2. Lack of time, not optimized for large groups

3. Simple code for easy use

4. Could be more user-friendly

The code does have problems tracking slower students or students who pass at the same time due to the sensor having a large FOV and being sensitive.


import time
from datetime import datetime
import serial

ser = serial.Serial('/dev/tty.SLAB_USBtoUART',baudrate=115200) #defaults to 8N1

# For each student added, simply repeat the code below.
# Each student requires two numbers. EX. Fourth student would be "time7 = time.time() and time8 = time.time()"
time1 = time.time()
time2 = time.time()

time3 = time.time()
time4 = time.time()

time5 = time.time()
time6 = time.time()

# Same as above, add a new lap with a new number for a new student
lap1 = 0
lap2 = 0
lap3 = 0

# Same as above, put in a variable(ex. cardId4) and make it equal to the cards ID

# After, adding the new lines for a new student above. Copy the paragraph starting with "if scanner == cardId2"

# Paste this underneath the last student "if scanner == cardId3"

# Change variables like "lap2 to lap4" and vice versa for "time" and change the "print 'Marley' to the student name

cardId1 = "1b390100110010603000300833b2ddd901400000000900b5"
cardId2 = "1b390100110010603000300833b2ddd901400000001400a8"
cardId3 = "1b390100110010603000300833b2ddd901400000000700bb"
while True:
    #time =
buffer =
    if (len(buffer)>0):
        scanner = buffer.encode('hex')
        if scanner == cardId1:
            lap1 += 1
print "Philip"
print str(lap1) + " Laps"
            time2 = time.time()
            print (time2 - time1)
            print "Lap Time"
#print str(time.hour) + " Hours"
            #print str(time.minute) + " Minutes"
            #print str(time.second) + " Seconds"

if scanner == cardId2:
            lap2 += 1
print "Marley"
print str(lap2) + " Laps"
            time4 = time.time()
            print (time4 - time3)
            print "Lap Time"
#print str(time.hour) + " Hours"
            #print str(time.minute) + " Minutes"
            #print str(time.second) + " Seconds"

if scanner == cardId3:
           lap3 += 1
print "Bob"
print str(lap3) + " Laps"
           time6 = time.time()
           print (time6 - time5)
           print "Lap Time"
#print str(time.hour) + " Hours"
           #print str(time.minute) + " Minutes"
           #print str(time.second) + " Seconds"



Leave a Reply