# Imports go at the top #TG4.py # Binary display during run # time tenths and hundredths separated in final display from microbit import * import time # show value 0-15 on given row def showbin(row,value): bit = (value%2)*9 value = int(value/2) display.set_pixel(4, row, bit) # column, row, brightness bit = (value%2)*9 value = int(value/2) display.set_pixel(3, row, bit) # column, row, brightness bit = (value%2)*9 value = int(value/2) display.set_pixel(2, row, bit) # column, row, brightness bit = (value%2)*9 value = int(value/2) display.set_pixel(1, row, bit) # column, row, brightness # wait for button A. Start of race while button_a.is_pressed()==False: time.sleep(0.01) if pin1.read_digital(): display.show("1") else: display.show("0") tstart = time.ticks_ms() t = 0 # column, row, brightness display.set_pixel(0, 0, 9) display.set_pixel(1, 1, 9) display.set_pixel(2, 2, 9) display.set_pixel(3, 3, 9) display.set_pixel(4, 4, 9) display.set_pixel(0, 4, 9) display.set_pixel(1, 3, 9) display.set_pixel(3, 1, 9) display.set_pixel(4, 0, 9) # display.show("X") # Run race waiting for B while button_b.is_pressed()==False: time.sleep(0.01) t+= 1 if ((t%10) == 0): showbin(0,int(t/100)) # row 0 seconds showbin(1,int(t/10)%10) # row 1 tenths digit # pause after race tend = time.ticks_ms() diff = time.ticks_diff(tend,tstart) display.clear() time.sleep(2) # display time: while True: display.show(int(t/100)) time.sleep(1) display.show(".") time.sleep(1) display.show(int(t/10)%10) time.sleep(0.5) display.clear() time.sleep(0.2) display.show(t%10) time.sleep(1) display.clear() time.sleep(2) display.show(str(diff/1000)) time.sleep(2)