How code is working out

Currently, my code is working well except for two bugs I have found recently. The first being that I need to implement a timestamp as the sensor is detecting the card multiple times. Including, that when the sensor is activated the time might be wrong.

My code remains the same detecting the current time and number of laps and this is an example of my first code that was to make sure I could detect the difference between each individual card.

import time

cardId1 = "300833B2DDD9014000000014"
scanner = raw_input()
if scanner == cardId1:
    print "good"
elif scanner != cardId1:
    print "no"

cardId2 = "300833B2DDD9014000000013"
scanner = raw_input()
if scanner == cardId2:
    print "good"
elif scanner != cardId2:
    print "no"

scanner = ["cardId1","cardId2"]
print scanner

#studentname2 = "Hamlet"
#print (studentname == studentname2)



#
# CARDS = ['300833B2DDD9014000000014']
# len(['300833B2DDD9014000000014'])
#
# if CARDS == True:
#     print (time.strftime("%I:%M:%S, Philip"))
# else:
#     print "Wrong card"

The simple code returns an answer "good" if the right card is inputed and "No" if not. 
After I recieved some help I created this code which could tell the exact lap and current time when a student passed the sensor. 
This is my second code version.
import time
from datetime import datetime


time = datetime.now()

lap1 = 0
lap2 = 0
lap3 = 0

cardId1 = "Philip"
cardId2 = "Jack"
cardId3 = "Charlie"
while True:
    scanner = raw_input()
    if scanner == cardId1:
        lap1 += 1
print str(lap1) + " Laps"
print str(time.hour) + " Hours"
print str(time.minute) + " Minutes"
print str(time.second) + " Seconds"
if scanner == cardId2:
        lap2 += 1
print str(lap2) + " Laps"
print str(time.hour) + " Hours"
print str(time.minute) + " Minutes"
print str(time.second) + " Seconds"
if scanner == cardId3:
       lap3 += 1
print str(lap3) + " Laps"
print str(time.hour) + " Hours"
print str(time.minute) + " Minutes"
print str(time.second) + " Seconds"

This code returns the number of current laps per student every time they pass the sensor and lists the current time.
The coach or runners job is to then subtract the current times per lap and calculate their times per lap or overall time.
Finally, this is my current and present code which will be my final version once I finish adding timestamps and fixing bugs.
import time
from datetime import datetime
import serial

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

#ser.open()
#ser.isOpen()






lap1 = 0
lap2 = 0
lap3 = 0

cardId1 = "1b390100110010603000300833b2ddd901400000000900b5"
cardId2 = "1b390100110010603000300833b2ddd901400000001400a8"
cardId3 = "1b390100110010603000300833b2ddd901400000000700bb"
while True:
    time = datetime.now()
    buffer = ser.read(ser.inWaiting())
    if (len(buffer)>0):
        scanner = buffer.encode('hex')
        if scanner == cardId1:
            lap1 += 1
print str(lap1) + " Laps"
print str(time.hour) + " Hours"
print str(time.minute) + " Minutes"
print str(time.second) + " Seconds"
if scanner == cardId2:
            lap2 += 1
print str(lap2) + " Laps"
print str(time.hour) + " Hours"
print str(time.minute) + " Minutes"
print str(time.second) + " Seconds"
if scanner == cardId3:
           lap3 += 1
print str(lap3) + " Laps"
print str(time.hour) + " Hours"
print str(time.minute) + " Minutes"
print str(time.second) + " Seconds"

Leave a Reply