Close

Part the Code

A project log for Path Lighting for Walker

A lighting rig that attaches to walkers to assist users to see where they are going in the dark.

scubabearscubabear 08/17/2015 at 18:310 Comments

Way back on Star Trek: First Contact I started using Microengineering Labs PICBASIC PRO compiler. I used PICBASIC to write the code for the Borg suits and the spacesuit lighting in that film... That was 19 years ago, and I still use it for simple projects because it is very fast for me to develop in. Here is the very simple program to operate the lighting here:

'written for PICBASICPRO V3
'author Alan McFarland
'August 16, 2015
'simple program to operate lighting for Harlan's walker
'uses PIC12F1501

DEFINE OSC 16		'define the clock speed so PICBASIC knows
OSCCON = $FF		'set speed to 16MHz

'******************************************************************************
'  SETUP 
'******************************************************************************	
	
	ADCON1 = %00001111			'port a is all digital IO 
    tape    con 3				'output pin to LED tape
    relay	var porta.2			'output port to control relay 
    pwmrate con 20000			'pwm freq
    faderate con 10				'delay in PWM loop to control duration of rate change
    level   var byte     
	count0          var word  
    
begin:
high relay				'as soon as the µC wakes up, turn on the relay to latch the power
hpwm tape,0, pwmrate
pause 250				'let settle
    
trigger:
for count0 = 0 to 255
    gosub fetch					'read in the sine value from the lookup table   
    hpwm tape,level, pwmrate	'send to hardware PWM & fade up to full
    pause faderate
next

for count0 = 1 to 50			'with a 2.3 second nap, this keeps light on for 115 sec
    NAP 7      ;nap for 2.3 seconds
next

for count0 = 0 to 255
    gosub fetch					'read in the sine value from the lookup table
    hpwm tape, 255 - level, pwmrate	'reverse the value since we are fading down
    pause faderate + 20				'make it longer to provide notice that its shutting off
next

low relay	'this will turn off power to the board

END 
       
fetch:
    lookup count0,[0,0,0,0,0,0,0,1,1,1,1,1,2,2,2,2,3,_
    3,3,4,4,4,5,5,6,6,7,7,8,8,9,9,10,11,11,12,13,13,14,15,16,16,_
    17,18,19,20,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,_
    42,43,44,45,46,48,49,50,51,53,54,55,56,58,59,60,62,63,64,66,67,69,70,71,73,_
    74,76,77,79,80,81,83,84,86,87,89,90,92,93,95,96,98,99,101,103,104,106,107,109,110,_
    112,113,115,117,118,120,121,123,124,126,128,_
    128,129,131,132,134,135,137,138,140,142,143,145,146,148,149,151,152,154,156,157,159,160,162,163,165,_
    166,168,169,171,172,174,175,176,178,179,181,182,184,185,186,188,189,191,192,193,195,196,197,199,200,_
    201,202,204,205,206,207,209,210,211,212,213,215,216,217,218,219,220,221,222,223,224,225,226,227,228,_
    229,230,231,232,233,234,235,235,236,237,238,239,239,240,241,242,242,243,244,244,245,246,246,247,247,_
    248,248,249,249,250,250,251,251,251,252,252,252,253,253,253,253,254,254,254,254,254,255,255,255,255,_
    255,255,255], level
    return

Discussions