' LAP COUNTER - PICAXE 20M2 ' (lapcounter_20m2.bas) '---------------------------------------------------------------------------------- ' Count up to 99 laps on a Jumbo 7segment display with links to select three modes. . '.Lap (LK1) steps one place each time the count buttom is pressed (0,1,2,3,4 etc). ' Even(LK2) steps two places each time the count button is pressed (0,2,4,6,8 etc). ' Odd (LK3) steps two places eacn time the count button is pressed (0,1,3,5,7 etc). ' Lap used for any sport on a track ie.running,cycling,motor bikes,go-carts etc. ' Even used when the Lap Counter is placed at the "start" end of the swimming pool ' Odd used when the Lap Counter is placed at the "other" end of the swimming pool. ' The power switch is also the reset switch - switch off to adjust the mode links. ' To extend battery life the display turns on for only 5 seconds each button press. ' You can use the check push button to view the lap count in the middle of any lap. ' You may also install a remote button operated by the competitor (see main text). '---------------------------------------------------------------------------------- set_micro:' ----------- initalise microprocessor - increase clock speed ----------- b0 = 0: b1 = 0: b2 = 0: b3 = 0: b4 = 0: let dirsB = %10111111: let dirsC = %10111111 let pinsB = %00000000: let pinsC = %00000000 setfreq m16 'goto set_mode set_mode:'------------- select "lap/even/odd" modes - display zero count ---------- readadc B.6,b3 if b3 > 180 and b3 < 200 then: let b4 = 1: endif' (lap) if b3 > 110 and b3 < 150 then: let b4 = 2: endif' (even) if b3 > 40 and b3 < 80 then: let b4 = 3: endif' (odd) gosub show_count if b4 = 3 then: let b0 = 1: endif 'goto count_units count_units:'---------- count "units" and save as b1 - display the count ---------- pause 4 gosub push_buttons '----------------- lap mode ---------------- if b4 = 1 then: inc b1: endif if b4 = 1 and b1 > 9 then: gosub count_tens: endif if b4 = 1 then: gosub show_count: endif '-------------- even/odd modes ------------- if b4 > 1 then: inc b0: inc b1: endif if b4 > 1 and b1 > 9 then: gosub count_tens: endif if b4 > 1 and b0 = 2 then: b0 = 0: gosub show_count: endif goto count_units count_tens:'----------- count "tens" and save as b2 - maximum is 99 laps ---------- inc b2 if b2 > 9 then goto set_micro let b1 = 0 return push_buttons:'--------- wait for the next "count/check" push button press --------- pause 10 readadc B.6,b3 if b3 > 200 then: gosub check_count: endif if pinC.6 = 0 then push_buttons return show_count:'----------- show count for 5 seconds each "count" button press -------- gosub drive_display pause 20000 let pinsB = %00000000: let pinsC = %00000000 return check_count:'---------- show count while the "check" push button is pressed ------- pause 10 gosub drive_display readadc B.6,b3 if b3 > 200 then goto check_count let pinsB = %00000000: let pinsC = %00000000 return drive_display:'---------- drive "units" and "tens" seven segment displays --------- '-------------- (units) --------------- if b1 = 0 then:pinsB = %00111111: endif if b1 = 1 then:pinsB = %00000110: endif if b1 = 2 then:pinsB = %10011011: endif if b1 = 3 then:pinsB = %10001111: endif if b1 = 4 then:pinsB = %10100110: endif if b1 = 5 then:pinsB = %10101101: endif if b1 = 6 then:pinsB = %10111100: endif if b1 = 7 then:pinsB = %00000111: endif if b1 = 8 then:pinsB = %10111111: endif if b1 = 9 then:pinsB = %10100111: endif '--------------- (tens) --------------- if b2 = 0 then:pinsC = %00000000: endif' (change to %00111111 to show leading zero) if b2 = 1 then:pinsC = %00000110: endif if b2 = 2 then:pinsC = %10011011: endif if b2 = 3 then:pinsC = %10001111: endif if b2 = 4 then:pinsC = %10100110: endif if b2 = 5 then:pinsC = %10101101: endif if b2 = 6 then:pinsC = %10111100: endif if b2 = 7 then:pinsC = %00000111: endif if b2 = 8 then:pinsC = %10111111: endif if b2 = 9 then:pinsC = %10100111: endif return ' Definition of variables '---------------------------------------------------------------------------------- ' b0 = two's count ( even/odd only) ' b1 = units count ( 0 to 9 ) ' b2 = tens count ( 0 to 9 ) ' b3 = mode input (analog ADC input) ' b4 = mode select (lap/even/odd) '---------------------------------------------------------------------------------- ' Microprocessor pin details ' (use if published circuit is wrong) '---------------------------------------------------------------------------------- ' pin name type use pin name type use ' 1 +V power positive 11 B.7 output disp1_g ' 2 Sin serial program 12 B.6 analog mode ' 3 C.7 output disp2_g 13 B.5 output disp1_f ' 4 C.6 input count 14 B.4 output disp1_e ' 5 C.5 output disp2_f 15 B.3 output disp1_d ' 6 C.4 output disp2_e 16 B.2 output disp1_c ' 7 C.3 output disp2_d 17 B.1 output disp1_b ' 8 C.2 output disp2_c 18 B.0 output disp1_a ' 9 C.1 output disp2_b 19 Sout serial program ' 10 C.0 output disp2_a 20 0V power negative '----------------------------------------------------------------------------------