; PICAXE 08M2 als NICAD meter gauge (4.8V / 4 cell).
; +---__---+
; +5 --|1 |-- GND
; Sin --| |-- Sout / OUT0
;ADC4 / OUT4 --| |-- ADC1 / OUT1
;IrIN / IN3 --| |-- ADC2 / OUT2
; +--------+
; ADC4 = input (22k to +6V, 10k to GND)
; OUT0 = multiplex driver (remaining LED pins)
; OUT1 = K(red), A(orange)
; OUT2 = K(yellow), A(green)
; Vcc via 1N4148 to +6V, 220nF to GND
fvrsetup FVR2048 ; set FVR as 2.048V
adcconfig %011 ; set FVR as ADC Vref+, 0V Vref-
main:
fvrsetup FVR2048 ; set FVR as 2.048V, FOR EACH READING RE-DO
readadc C.4,b1 ; read value into b1
if b1 < 180 then flsh ; jump to flsh if voltage < 4.6V
if b1 < 186 then lowbat ; jump to lobat if 4.8V
if b1 < 193 then minimal ; jump to flsh if 5.0V
if b1 < 200 then nominal ; jump to flsh if > 5.2V
goto maximal
flsh:
;debug b1
high C.0 ; flash RED outputs
low C.1
high C.2
pause 200 ; wait 200 mseconds
low C.0 ; switch on output RED
low C.1
low C.2
pause 200 ; wait 200 mseconds
goto main ; loop back to start
lowbat:
;debug b1
high C.0 ; switch on output RED
low C.1
high C.2
pause 10 ; wait 10 mseconds
low C.0 ; switch on output RED
low C.1
low C.2
pause 4 ; wait 10 mseconds (incudin ADC)
goto main ; loop back to start
minimal:
;debug b1
high C.0 ; switch on output RED+ORANGE
low C.1
high C.2
pause 10 ; wait 10 mseconds
low C.0 ; switch on output RED
high C.1
low C.2
pause 4 ; wait 10 mseconds (incudin ADC)
goto main ; loop back to start
nominal:
;debug b1
high C.0 ; switch on output RED+ORANGE+YELLOW
low C.1
low C.2
pause 10 ; wait 10 mseconds
low C.0 ; switch on output RED
high C.1
low C.2
pause 4 ; wait 10 mseconds (incudin ADC)
goto main ; loop back to start
maximal:
;debug b1
high C.0 ; switch on output RED
low C.1
low C.2
pause 10 ; wait 10 mseconds
low C.0 ; switch on output RED
high C.1
high C.2
pause 4 ; wait 10 mseconds (incudin ADC)
goto main ; loop back to start