#picaxe 08m2
#no_data
#terminal off
symbol PCF8566=$7C
symbol in=4
symbol menu=pin3
symbol light=0
symbol speed=w0
symbol counter=b2
symbol nr1=b3
symbol nr2=b4
symbol nr3=b5
symbol wheel=b6
symbol distance=w4
symbol paus=100
read 0,wheel
distance=wheel*36*10
hi2csetup i2cmaster,PCF8566, i2cfast, i2cbyte
gosub init_display
setint $0,$10
main:
if pin4 = 1 then gosub back
gosub display_animation
goto main
interrupt:
gosub clear_display
hi2cout 0,(%00001000)
hi2cout 4,(%11010111)
hi2cout 6,(%11011111)
hi2cout 8,(%11010111)
read_speed:
pulsin in,1,speed
pulsin in,1,speed
if speed=0 then show_speed
speed=speed/100
speed= distance/speed
if speed>1000 then:speed=0
endif
if speed=0 then show_speed
counter=0
show_speed:
if speed=0 then: counter=counter+1
endif
if counter=>2 then back1
if speed=0 then read_speed
let nr1=speed/100
let nr2=speed//100/10
let nr3=speed//10
lookup nr1,(%11010111,%000000110,%11100011,%10100111,%00110110,%10110101,%111110101,%00000111,%11110111,%10110111),nr1
lookup nr2,(%11011111,%000001110,%11101011,%10101111,%00111110,%10111101,%111111101,%00001111,%11111111,%10111111),nr2
lookup nr3,(%11010111,%000000110,%11100011,%10100111,%00110110,%10110101,%111110101,%00000111,%11110111,%10110111),nr3
hi2cout 0,(%00001000)
hi2cout 4,(nr1)
hi2cout 6,(nr2)
hi2cout 8,(nr3)
goto read_speed
back:
setint $0,$10
counter=0
gosub clear_display
return
back1:
gosub clear_display
setint off
return
calib:
setint off
gosub clear_display
calib1:
let nr1=wheel/100
let nr2=wheel//100/10
let nr3=wheel//10
lookup nr1,(%11010111,%000000110,%11100011,%10100111,%00110110,%10110101,%111110101,%00000111,%11110111,%10110111),nr1
lookup nr2,(%11010111,%000000110,%11100011,%10100111,%00110110,%10110101,%111110101,%00000111,%11110111,%10110111),nr2
lookup nr3,(%11010111,%000000110,%11100011,%10100111,%00110110,%10110101,%111110101,%00000111,%11110111,%10110111),nr3
hi2cout 4,(nr1)
hi2cout 6,(nr2)
hi2cout 8,(nr3)
wheel=wheel+1
if wheel=>181 then:wheel=100
endif
pause 200
if menu=0 then calib1
store:
pause 500
write 0,wheel
distance=wheel*36*10
gosub clear_display
return
display_animation:
hi2cout 2,(%11100110) 'D
pause paus
if menu=0 then gosub calib
hi2cout 4,(%11110001) 'E
pause paus
if menu=0 then gosub calib
hi2cout 6,(%01100000) 'R
pause paus
if menu=0 then gosub calib
hi2cout 8,(%11110100) 'B
pause paus
if menu=0 then gosub calib
hi2cout 10,(%00000110) 'I
pause 400
if menu=0 then gosub calib
hi2cout 2,($0)
pause paus
if menu=0 then gosub calib
hi2cout 4,($0)
pause paus
if menu=0 then gosub calib
hi2cout 6,($0)
pause paus
if menu=0 then gosub calib
hi2cout 8,($0)
pause paus
if menu=0 then gosub calib
hi2cout 10,($0)
pause paus
if menu=0 then gosub calib
return
clear_display:
hi2cout 0,($0,$0,$0,$0,$0,$0,$0,$0,$0,$0,$0)
return
init_display:
high light
hi2cout (%11001000,%10000000,%11100000,%11111000,%01110000)
pause 10
gosub clear_display
pause 10
hi2cout 0,($FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF)
wait 2
gosub clear_display
return