One way to light a stairway

newplumber

Senior Member
Hello
I have completed my stair led project and of course I will add more to it (still thinking about a lighted hand rail with a cool/horrible idea)
I will update this page when I have more information or need corrections
but here is the start of my finished stair project.
Thanks again for everyone here on all the help.
Code:
' CODE is for picaxe 20X2 and for two sets of white (no RGB) APA102 LED strips
' with two SR501 motion sensors for the top and bottom of stairs, picaxe wires to the led strips 
' start at the bottom of the stairs. 
'bottom sensor = B.0.....top sensor = B.1
#picaxe 20x2  
#no_table
#no_data
setfreq m64
Let DIRSB = %10000000 : Let DIRSC = %00000010
; Set how many LED modules in the strip
symbol HOW_MANY_LEDS = 141 ;<-- how many leds you have to flow up/down on stairs (mine took 141)

; Set the brightness of the LED while testing
; Use small values to keep current consumption low
symbol brightLED  = 180 ; 0 to 255 (full)
symbol dimLED     = 10  ; 0 to 255 (full)
symbol Ptime      = 200 ; pause time 
; Initialise the HSPI interface
#macro init()
  hspisetup spimode00, spimedium
#endmacro

; Send a four byte packet out via HSPI
#macro sendPacket( n1, n2, n3, n4 )
  hspiout( n1, n2, n3, n4 )
#endmacro

; Send the start of data header
#macro head()
  sendPacket( $00 ,$00 ,$00 ,$00 )
#endmacro

; Send a LED controlling command
#macro send( red, white, blue)
  sendPacket( $FF, red, white, blue ) ' send packet ups or fedex you choose :)
#endmacro

; Send the end of data tail
#macro tail()
   sendPacket( $00 ,$00 ,$00 ,$00 )'1-64
   sendPacket( $00 ,$00 ,$00 ,$00 )
   sendPacket( $00 ,$00 ,$00 ,$00 )
#endmacro

; Turn a single LED off
#macro ledOff
  send( $00, $00, $00 )
#endmacro

; Turn LED on bright
#macro LEDbright
  send(  $00, $00,brightLED )
#endmacro

; Turn LED on dim
#macro LEDdim
  send(  $00, $00,dimLED )
#endmacro

PowerOnReset:

  ; Initialise the HSPI interface
  init
     head
  for b1 = 1 to HOW_MANY_LEDS ' makes all leds off 
    ledOff
  next b1
  tail 
  pause 2000
START:
   gosub All_On_dim ; Turns all leds on dim
   pause 200
DO : pause Ptime
  IF pinb.0 = 1 then gosub LEDS_ON_FROM_BOTTOM ' check bottom sensor
  IF pinb.1 = 1 then gosub LEDS_ON_FROM_TOP    ' check top sensor
LOOP

 LEDS_ON_FROM_BOTTOM:' flows leds UP on bright
  FOR b1 = 1 to HOW_MANY_LEDS
  head	  
   FOR b2 = 1 to b1
    LEDbright
   NEXT b2
 b3 = HOW_MANY_LEDS - b1
   If b3 = 0 then PASS_LED_dim 
  FOR b2 = 1 to b3
   LEDdim
  NEXT b2
 PASS_LED_dim:
  tail
  NEXT b1
 STAY_ON_BRIGHT: W4 = 0
DO : Pause Ptime : inc W4
  IF PINB.1 = 1 and PINB.0 = 0 then LEDS_OFF_FROM_BOTTOM 'if top sensor = 1 then turn leds back to dim 
  IF PINB.1 = 0 and PINB.0 = 1 then STAY_ON_BRIGHT 'if bottom sensor = 1 then keep leds bright 
  IF PINB.1 = 1 and PINB.0 = 1 then STAY_ON_BRIGHT 'if both sensors = 1 then keep leds bright
LOOP until W4 = 2  ' if both sensors = 0 then wait a while then turn to dim 
 LEDS_OFF_FROM_BOTTOM: ' flows leds UP on dim
  FOR b1 = 1 to HOW_MANY_LEDS
  head	  
   FOR b2 = 1 to b1
    LEDdim
   NEXT b2
 b3 = HOW_MANY_LEDS - b1
   If b3 = 0 then PASS_LED_bright
  FOR b2 = 1 to b3
   LEDbright
  NEXT b2
 PASS_LED_bright:
  tail
  NEXT b1
RETURN

 LEDS_ON_FROM_TOP:' flows leds DOWN on bright
  FOR b1 = HOW_MANY_LEDS to 1 step -1
  head
  b5 = b1 -1
  if b5 = 0 then skip_LEDdim
   FOR b2 = b5 to 1 step -1
    LEDdim
   NEXT b2
skip_LEDdim:
 b3 = 1 + HOW_MANY_LEDS - b1
  FOR b2 = 1 to b3
   LEDbright
  NEXT b2
  tail
  NEXT b1
 STAY_ON_BRIGHT1: W4 = 0
DO : Pause Ptime : inc W4
  IF PINB.1 = 0 and PINB.0 = 1 then LEDS_OFF_FROM_TOP 'if bottom sensor = 1 then turn leds back to dim 
  IF PINB.1 = 0 and PINB.0 = 1 then STAY_ON_BRIGHT1   'if top sensor = 1 then keep leds bright 
  IF PINB.1 = 1 and PINB.0 = 1 then STAY_ON_BRIGHT1   'if both sensors = 1 then keep leds bright
LOOP until W4 = 2   ' if both sensors = 0 then wait a while then turn to dim 
 LEDS_OFF_FROM_TOP:' flows leds DOWN on dim
  FOR b1 = HOW_MANY_LEDS to 1 step -1
  head
  b5 = b1 -1
  if b5 = 0 then skip_LEDbright
   FOR b2 = b5 to 1 step -1
    LEDbright
   NEXT b2
skip_LEDbright:
 b3 = 1 + HOW_MANY_LEDS - b1
  FOR b2 = 1 to b3
   LEDdim
  NEXT b2
  tail
  NEXT b1
RETURN

All_On_dim:
  head
  for b1 = 1 to HOW_MANY_LEDS
   LEDdim
  next b1
  tail
RETURN
MATERIAL/PRICE LIST
Stair steps = 16_____free
2- reels of cool white apa102 led strips = $60 usd
4- 1"X12"X8' MDF boards = $100 usd
1- gallon of super gloss white paint = $34 usd
1- picaxe 20X2 chip from picaxe.com = $4 usd
2- 100 uf caps price NA ( I have all mine from auctions)
1- 10 uF cap price NA
1- .01 uF cap price NA
2- 300 ohm resistor price NA
1- 22k ohm resistor price NA
1- 10k ohm resistor price NA
1- 5 amp fuse+ holder price NA
1- PC power supply 5 volt 15 amp price $1.00 usd (older pc)
1- pcb board from Lbenson drawning to oshpark = $3 usd
4- weeks of learning from cool picaxe forums poeple = priceless
3- days for install..or 1 1/2 days without kids but we had fun :)
Total cost est = 250 usd
Total time est for me = 6 years 4.5 months
Total time for a pro = 2 hours 3.5 minutes
your always late for work friend
Mark
 

Attachments

Last edited:
Top