'LEDNAP.BAS program for September "Silicon Chip" Picaxe-08 article. Ver 1.0 12/7/03 'Potentiometer acts as multi position switch! Stan. SWAN => s.t.swan@massey.ac.nz 'Values as set here allow 7 different flash types to be dialled up via the 500k pot 'Much tweaking still possible-better reading b0 ranges,alter pot(Log?),R value etc 'White LED (10mm ?) via BC547 with 470 Ohms from its base to Picaxe pin 2 via "NAP". 'Actual nap value depends on application - steady light,standby, rescue beacon etc 'Even nap 0 has distinctive ~20 Hz flicker = ideal bike front for attention getting? 'NB ~10Hz flicker is most irritating to many observers - may cause epileptic fit?! 'On 3AA 4.5V supply & 470 base R,typical DSE Lux meter values (pulsed of course) ~ 'nap 0=35mA 340 Lux, nap 1=22mA 216 Lux, nap 2= 13mA 120 Lux, nap 3= 8mA 70 Lux 'nap duration = 2^period x ~18ms , with period values 0-7 ( rolled over if beyond ) 'nap 0 ~18ms, nap 1 ~36ms, nap 2 ~72ms, nap 3 ~144ms, nap 7 ~ 2secs 'Inbuilt loop o'head of course distorts M/S ratio. Red LED direct driven from pin 4 'Program download from => www.picaxe.orcon.net.nz/lednap.bas Comments (') optional '-------------------------------------------------------------------------------- ledflash: 'main adc read to set nap time or dim with pwm etc readadc 1,b0 'ADC read pin1 -via 500k pot(Log?) & 47k V.divider b1= b0/22 'divide returned "nap" value so fits in 0-7 range if b1=0 then redflash '"08" readadc values are in 16 blocks 0-160,11 wide if b1=1 then redpwm 'Could use as is,but division OK for just 7 values if b1=7 then beacon '1/2 Hz beacon mode nap 7 forced via b2 variable '--------------------------------------------------------------------------------- whiteflash: 'routine for normal adjustable white flash rates b2=b1-2 'tweak returned b1 rates,since too short as divided high 2:pause 10:low 2 'LED pulse - somewhat overdriving via transistor nap b2 'brief snooze to allow LED/BC547 cool down ! goto ledflash 'return to main pot. reading procedure '--------------------------------------------------------------------------------- redflash: 'red led at pin 4 flash - rear bike light style high 4:pause 10:low 4:nap 7 'pulsed ~ every 2 seconds - adjust to suit needs goto ledflash 'return to main pot. reading procedure '--------------------------------------------------------------------------------- redpwm: 'red led attractive pulsing effect for b3=0 to 255 step 2 'loop so red LED has pleasing brightness increase pwm 4,b3,1 :next b3 'PWM pin 4 LED one cycle at increasing pulse width for b3=255 to 0 step -2 'loop to fade led out pwm 4,b3,1 'PWM pin 2 led one cycle at decreasing pulse width next b3:pause 300 'led displays a pleasing "heartbeat" effect ! goto ledflash 'return to main pot. reading procedure '--------------------------------------------------------------------------------- beacon: 'battery life prolonging (weeks ?) beacon flash high 2:pause 10:low 2 'brief led pulse - via transistor.Approx 1mA draw nap 7 '~ 2 sec delay between pulses goto ledflash 'return to main pot. reading procedure