' Test Chasing LEDs
' 208 LEDs in 16 column x 13 row matrix
' 21 Jan 12
' 25 Jan 12 add Batt_Check
' 04 Feb 12 add pushbutton for slow speed
' 05 Feb 12 16MHz, all pauses 2x
' 16 Feb 12 v5 add row_12 on A.5
' 22 Feb 12 v6 update pulsetimes
' 27 Feb 12 v7 addl debug msg
' 19 Apr 12 v8 adjust battery warn levels
#picaxe 40X2
#no_data
#no_table
#terminal 19200
'#define verbose ; for debug messages
setfreq m16 ; 8MHz default, 16MHz max w/o res
'-----------------------------------------
' I/O definitions
symbol PushB = pinA.6 ; Push Button to +V on pin 9
symbol Knob = 7 ; 20k pot on ADC7 - A.7,pin 10
symbol Col_MSB = outpinsC ; Column bits [15:8]
symbol Col_LSB = outpinsD ; Column bits [ 7:0]
symbol Row_MSB = outpinsA ; Row bits [12:8]
symbol Row_LSB = outpinsB ; Column bits [ 7:0]
Col_MSB = %00000000 ; Init
Col_LSB = %00000000
dirsC = %11111111
dirsD = %11111111
Row_MSB = %00101111 ; skip A.4 (SerOut)
Row_LSB = %11111111
dirsA = %00101111
dirsB = %11111111
adcsetup = 0x0080 ; enable ADC7 (pin 10)
' Program definitions
symbol row = b10
symbol col = b11
symbol LED_Num = b12
symbol time_multiplier = b13
symbol on_time = w10 ; b20,b21
symbol pulse_time = w11 ; b22,b23
symbol pulse_time2 = w12 ; b24,b25
symbol on_time_M = w13 ; b26,b27
symbol pulse_time_M = w14 ; b28,b29
symbol pulse_time_M2 = w15 ; b30,b31
'=========================================
main:
pause 100
sertxd("208 Chasing LEDs (40X2) v8", cr,lf)
time_multiplier = 1
if PushB is ON then
Col_MSB = $00 ; light (0,0) LED for current meas.
Col_LSB = $01
Row_MSB = $2F
Row_LSB = $FE
do loop until PushB is OFF
pause 100
endif
again:
readadc Knob,b0 ; read speed adj (0-255)
sertxd("Knob: ",#b0, cr,lf)
on_time = b0 / 2 ; 0-127 ( 0-63 msec)
pulse_time = on_time * 3 / 4 ; 75% delay
pulse_time2 = on_time / 2 ; 50% delay
GOSUB Setdelays
#ifdef verbose
sertxd("OnTime: ",#on_time, " Mult: ", #time_multiplier,cr,lf)
sertxd("Pulse: ",#pulse_time, " Pulse2: ",#pulse_time2,cr,lf)
#endif
Row_MSB = $2F
Row_LSB = $FF
for row = 0 to 12
Col_MSB = $00
Col_LSB = $00
w0 = 1 << row
if row=12 then : w0 = w0 <<1 : endif ; skip A.4, use A.5
Row_LSB = NOT b0
Row_MSB = b1 XOR $2F
#ifdef verbose
sertxd("Row info: ",#row, " ",#Row_MSB," ",#Row_LSB, cr,lf)
#endif
for col = 0 to 15
w0 = 1 << col
Col_LSB = b0
Col_MSB = b1
#ifdef verbose
sertxd("Col info: ",#col, " ",#Col_MSB," ",#Col_LSB, cr,lf)
#endif
LED_Num = row * 16 + col ; 0 to 207
select LED_Num
case 28 to 67
pause pulse_time_M
case 68 to 119
pause pulse_time_M2
case 120 to 131
pause pulse_time_M
else
pause on_time_M
endselect
if PushB is ON then gosub PushButton
next col
next row
Col_MSB = $00
Col_LSB = $00
gosub Batt_Check
for b0 = 1 to 1
pause 100
if PushB is ON then gosub PushButton
next b0
goto again
end
'=======================================
PushButton:
' If pushbutton was pressed, then toggle multiplier
sertxd("Button pressed.",cr,lf)
time_multiplier = time_multiplier XOR $04
do loop until PushB is OFF
pause 100 ; debounce
Setdelays:
on_time_M = on_time * time_multiplier + 1
pulse_time_M = pulse_time * time_multiplier
pulse_time_M2 = pulse_time2 * time_multiplier
return
'-----------------------------------------
Batt_Check:
' Measure internal reference to check +V power
symbol ADCval = w26
symbol V_plus = w27 ; *100 volts
calibadc10 ADCval
; V_plus / 1023 = 1.024 / ADCval
; 100 x V_plus = 100 x 1047.552 / ADCval
; 100 x V_plus = 52377.6 / ADCval * 2
V_plus = 52378 / ADCval
V_plus = V_plus * 2
sertxd ("+V * 100 = ", #V_plus,cr,lf)
'bintoascii V_plus, b4,b3,b2,b1,b0
'sertxd (#ADCval," counts, ",b2,".",b1,b0, " volts",cr,lf)
' new is ~ 4.6V
if V_plus<380 then gosub Blink_LED00 ; < 3.8 V
if V_plus<360 then gosub Blink_LED00 ; < 3.6 V
if V_plus<330 then gosub Blink_LED00 ; < 3.3 V
return
'---------------------------------------
Blink_LED00:
; alert, blink the first LED
Col_MSB = $00
Col_LSB = $01
Row_MSB = $2F
Row_LSB = $FE
pause 500
Col_MSB = 0 ; all off
Col_LSB = 0
Row_MSB = $2F
Row_LSB = $FF
pause 500
return
'---------------------------------------
#rem
Battery Life:
3x D cells = 3 x 12,000 mAh
circuit current = 24.5 mA
life = 61 days