' programmable strobe flashlight ' 10 2006 by Medcosm, LLC ' ' originally created to see if it worked well looking at individual drops of water ' coming out of a faucet, a la the "Time Fountain" ' can use 2 LEDs hooked up to 2 output pins gives more current and brighter light ' ' ' Use this prog w/ Simple Digital Strobe V2 circuit ' 'hardware hookups for this project symbol LED1=1 'LED1 symbol LED2=2 'LED2 use 2 LEDs for more bightness symbol BUTN1=pin3 'N.O. pushbutton 1 symbol BUTN2=pin4 'N.O. pushbutton 2 'declare variable space symbol mode=b0 'mode symbol curstep=w2 'step size symbol LEDoffTime=w3 'pause delay symbol buttonCount=w4 'count how many cycles button pressed symbol var1=b10 'local variable symbol var2=b11 'local variable symbol devcnt=w6 'counts how long device is off 'static vars symbol LEDpulseval=120 'brightness of LED during pulse mode symbol devoffcnt=60 'how often to flash when off? 30/.576, approx 30 seconds symbol LEDonTime=1 'LED on delay (ms) symbol minStep=1 'min step size (ms) symbol maxStep=50 'max step size symbol stepDiff=maxStep-minStep symbol minDelay=3 'min LED off delay symbol maxDelay=300 'max LED off delay symbol modeOff=0 'off mode symbol modeStrobe=1 'strobe mode symbol maxStepCount=50 'count to reach max step symbol pulseStepSize=12 'heartbeat brightness step size init: LEDoffTime=16 '60 Hz mode=modeOff gosub pulseled start: if BUTN1=1 and BUTN2=1 and mode=modeOff then setModeOn if BUTN1=1 and BUTN2=1 and mode=modeStrobe then setModeOff if mode=modeOff then devOff strobe: if BUTN1=1 or BUTN2=1 then changeDelay buttonCount=0 buttonRet: high LED1 'flash LED high LED2 pause LEDonTime low LED1 low LED2 pause LEDoffTime 'debug goto start setModeOn: mode=modeStrobe goto setModeEnd setModeOff: mode=modeOff goto setModeEnd setModeEnd: pause 300 'wait a fraction of a second goto start changeDelay: buttonCount=buttonCount+1 curStep=buttonCount*stepDiff/maxStepCount if curstep>=minStep then stepMinOK curstep=minStep stepMinOK: if curstep<=maxStep then stepMaxOK curstep=maxStep stepMaxOK: if BUTN1=1 then incDelay decDelay: if curStep>LEDoffTime then buttonRet LEDoffTime=LEDoffTime-curStep goto delayRet incDelay: LEDoffTime=LEDoffTime+curStep delayRet: if LEDoffTime>=minDelay then delayMinOK LEDoffTime=minDelay delayMinOK: if LEDoffTime<=maxDelay then delayMaxOK LEDoffTime=maxDelay delayMaxOK: goto buttonRet 'devOff: 'powerdown for a bit to save battery ' nap 5 ' goto start 'device is off, pulses occasionally to let use know where it is devOff: devcnt=devcnt+1 if devcnt < devoffcnt then devoffend gosub pulseled devcnt=0 devoffend: nap 5 goto start 'pulse LED pulseled: for var1= 0 to LEDpulseval step pulseStepSize ' counter loop so LED has multiple PWM cycles pwm LED1,var1,12 ' PWM pin 2 LED one cycle increasing pulse width var2=var1+pulseStepSize/2 pwm LED2,var2,12 ' PWM pin 2 LED one cycle increasing pulse width next ' effect is a pleasing surging brightness increase for var1= LEDpulseval to 0 step -pulseStepSize ' When warm b2 decreases so step less/beat faster pwm LED1,var2,12 ' PWM pin 2 LED one cycle decreasing pulse width var2=var1+pulseStepSize/2 pwm LED2,var1,12 ' PWM pin 2 LED one cycle decreasing pulse width next ' gives a fading brightness instead of sudden off return