LED Strip Control

Axel87

Senior Member
Looking for a good controller to run multiple LEDS AND automotive lamps.

http://www.ebay.com/itm/400493404904?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1439.l2649

Looking at a 4511, just cus I have it handy at this moment.
The 2003 would be pretty weak for this correct?
I would like to have a pin always on if key is on.
assortment of channels to control leds on/off or a sweep through them would be cool.
As far as the automotive lamps, I am not sure what the current draw is common on these.
14m2 Picaxe
12v supply w a 7805 for 5v supply.
5v supply circuit design off the picaxe manual
If my math is correct 12v-24W-300leds. Gives me a 6mA draw per led. Is this correct?

Hope someone has a better idea as far as a driver for this
Thanks again!
 
Last edited:

Haku

Senior Member
You want to be able to control the individual LEDs on a long strip, or turn on/off the whole strip at once?

For driving a whole LED strip and automotive lamps I suggest MOSFETs as they come in beefy versions capable of switching high amps without fuss. I've got a Picaxe controlling 10 meters of 5050 type LEDs lighting this room all driven off a single MOSFET which allows me to set the brightness through PWM.

For controlling individual LEDs in a strip it gets tricky, and expensive. I've only seen RGB LED strips with individually addressable LEDs and they're around the $30-$45 mark for just 1 meter.
 

Axel87

Senior Member
I had imagined using a couple pins of the picaxe to control different sections of the stip, this one you can cut every 3. so lets say 4 channel's of 12 leds.
There are also 4 automotive lamps.
I am working on using a 4401 with a relay right now, but so far im all over the place with this one ;) so that idea might change.
I thought about using a MOSFET but expensive device for multiple channels, and I have lots of smaller transistors laying around.
Thanks for the input
 

rossko57

Senior Member
Look at your automotive lamps to see what wattage they are. This gives you a clue for the current you need to handle. Decide if you want on/off control or variable brightness. This narrows down the technologies you can choose from. Decide if you want all the lamps working together, or doing different things. This gives a clue to how many channels you need to build,
 

Hemi345

Senior Member
I had imagined using a couple pins of the picaxe to control different sections of the stip, this one you can cut every 3. so lets say 4 channel's of 12 leds.
There are also 4 automotive lamps.
I am working on using a 4401 with a relay right now, but so far im all over the place with this one ;) so that idea might change.
I thought about using a MOSFET but expensive device for multiple channels, and I have lots of smaller transistors laying around.
Thanks for the input
I used a 14M2 to build my own RGB strip controller. Your application (atleast with the LED strip), would be very similar with the addition of an additional channel for your 4th strip of white LEDs. Here's a schematic and PCB I made:
 

Attachments

Axel87

Senior Member
Whats wrong w my code?
Code:
; ****************************************************************************************************
; _______ _________ _        _______  _______   _______           _______  _______  ______  
;(       )\__   __/( (    /|(  ___  )(  ____ ) (  ____ \|\     /|(  ___  )(  ____ )(  __  \ 
;| () () |   ) (   |  \  ( || (   ) || (    )| | (    \/| )   ( || (   ) || (    )|| (  \  )
;| || || |   | |   |   \ | || |   | || (____)| | |      | (___) || |   | || (____)|| |   ) |
;| |(_)| |   | |   | (\ \) || |   | ||     __) | |      |  ___  || |   | ||     __)| |   | |
;| |   | |   | |   | | \   || |   | || (\ (    | |      | (   ) || |   | || (\ (   | |   ) |
;| )   ( |___) (___| )  \  || (___) || ) \ \__ | (____/\| )   ( || (___) || ) \ \__| (__/  )
;|/     \|\_______/|/    )_)(_______)|/   \__/ (_______/|/     \|(_______)|/   \__/(______/ 
;                                                                                                      		                          
; ****************************************************************************************************
;    Filename: 		
;    Date: 			
;    Target PICAXE:
; ****************************************************************************************************


	init:  let b0= 0
	
	main:  if b0 = 1 then add
		goto flash
		
	add:   let b0= b0+1
		if b0 < 4 then main
		high 1
		debug
		goto main
		
	flash:	
		high b.5
		high b.4
		pause 1000
		low b.5 
		low b.4
		pause 1000 
		goto flash
NO switch on b0
LED on b.4 and TIP120 w relay of b.5
Need the switch high for 100 count x2 activates flash
In flash another press of switch cancels, back to main
(I know that last parts not in there;)
Any clues? Pointers?
 

g6ejd

Senior Member
In your code I think you have assumed that b0 is BIT 0, it isn't it means BYTE 0 so your first test will only pass every 255 loops, was that your intention? Plus when it gets to flash: it will stay there looping around forever, was that your intention?
 

westaust55

Moderator
Whats wrong with my code?


NO switch on b0

Any clues? Pointers?
DO you mean that your NO contact switch is on pin B.0 ?
You need to check the IO pin B.0 not the byte variable b0 to ascertain the state of the switch.

Code:
HoldTillHigh:
        IF pinB.0 = 0 THEN HoldTillHigh


as a side note with respct to indenting of labels in your program listing:
From PICAXE manual 2 on the page for LABELS (p5)
It is convention to only place labels on the left hand side of the screen.
All other commands should be indented by using the &#8216;tab key&#8217;.
This convention makes the program much easier to read and follow.
 

Axel87

Senior Member
I copied the code from my editor, I do have indents in the code. Ill look into this.
It doesn't seem to count the on/off of the switch. But seems to count closed time.
Once again, would like to have it count switch closed 5 times to activate flash program.
I got the first part of the code from the manual, micro switches section I believe.
The no would go to b0 and common to ground, correct?
 

Axel87

Senior Member
Hey guys,

I understand now what you mean westaust55 about indenting, you mean that I shouldent have indented the program names correct?
I just did this because it seemed to read easier/cleaner to me, but Ill switch it before it becomes a habit ;)
Just wondering if anyone had anymore ideas?
I dont see the tie with what I was reading in the manual and HOLDTILLHIGH command, I havent encountered this word before.
Have I forgotten to provide you with anymore needed infomation?
Sorry this code is so scattered, I thought I copied it directly from the manual, but it appears I copied my fixing attempt not the original code, sorry folks ;/
I will get back to you later with what I had used from the manual

init: let b0= 0 - I am not sure what this does?? This sets a count to memory or bit correct?

main: if b0 = 1 then add -so that when b0 is high it adds one then goes to flash
goto flash

add: let b0= b0+1 - again, confused as what this command does, b0 already has a count on it
if b0 < 5 then main
high 1
goto main

flash:
high b.5
high b.4
pause 1000
low b.5
low b.4
pause 1000
goto flash
 

Axel87

Senior Member
Below is the code I tried to copy(Picaxe manual 3)-

The following two programs show the effect of switch bouncing. The program should
light the LED on pin1 when the switch connected to pin0 has been pressed more than
5 times. However, the first listing may not work correctly, because the microcontroller
may count &#8216;bounces&#8217; rather than actual pushes, and so the LED may light prematurely.

init: let b0 = 0

main: if pin 1 = 1 then add
goto main

add: let b0 = b0 + 1
if b0 < 5 then main
high 1
goto main
init: let b0 = 0
main: if pin 1 = 1 then add
goto main
add: pause 100 &#8216;short delay
let b0 = b0 + 1
if b0 < 5 then main
high 1
goto main

From there I added the Flash: section
 

bfgstew

Senior Member
What do you want this code to do, in simple terms?
You have main duplicated and init and add??????????????? All very confusing.
 

Axel87

Senior Member
Sorry copied the code wrong.

init: let b0 = 0
main: if pin 1 = 1 then add
goto main
add: let b0 = b0 + 1
if b0 < 5 then main
high 1
goto main

I think I figured out my problem. (noob ;) mistake )
I believe I was using b.0 instead of c.0. But I am away from the project for the week traveling.
I do apologize for the confusion on these posts.
To claify my suspision, using a 14m2- one uses b.0 OR c.o as input and b0 OR c0 as an output. correct?
Example

Main
if b.0 high then c0 high
or
if c.0 high then b0 high

The . denotes a input vs an output?
 

bfgstew

Senior Member
????
b0 is a byte variable, B.0 is a pin.
pinC.0 or pinB.0 I think is correct, rather than c0 or b0.
 

rossko57

Senior Member
one uses b.0 OR c.o as input and b0 OR c0 as an output. correct?
NO. Nothing like that.
It's probably worth re-reading Picaxe manual number 2
http://www.picaxe.com/docs/picaxe_manual2.pdf
See the "variables" section;
b0 , wo, bit0 and so on are internal variables for use by your BASIC program. They have absolutely no connection with the outside world.
Also in manual 2, the "input / ouput" section;
b.0, c.2 are actual pins on the chip, they might be inputs or outputs depending on the usage.
 

bfgstew

Senior Member
Try this

Code:
init: let b0 = 0
main:
do
 if pinB.1 = 1 then 
 inc b0
 if b0 = 5 then goto flash
 endif
 loop
flash: 
high b.5
high b.4
pause 1000
low b.5 
low b.4
pause 1000 
goto init
 

bfgstew

Senior Member
N/O or n/o denotes a normally open switch.
b0, b1, b2 etc denotes a byte variable
w0, w1, w2 etc denotes a word variable.
B.0, B.1, C.0, C.1 etc denotes a pin.

As mentioned earlier, read up on variables and pin configurations in the manuals, it will save a lot of confusion.
 

Axel87

Senior Member
Try this

Code:
init: let b0 = 0
main:
do
 if pinB.1 = 1 then 
 inc b0
 if b0 = 5 then goto flash
 endif
 loop
flash: 
high b.5
high b.4
pause 1000
low b.5 
low b.4
pause 1000 
goto init
[/QUOTE

Thank you offering a hand on this !
I tried your code, and it seems to be what I was aiming at with one promblem( besides learning the new commands ;/)
As I dont have the ability to acess my project right now, i am just running simulations. but it seems to count 5 'runs' though the code then go to flash.
I am looking to have it actually count the switch close and open.

What I am wondering now is which commands to use, and HOW do i search for the one I want (for future projects)
Ones with more experience, how do you find these commands? Or do you simply just stumple upon them?
I do have the picaxe manual 2 command ref but theres alot of information there to soak in, have you memorized this or do you have a technique searching for needed commands? ( I dont mean ctl f)

As always
Thanks again to everyone
 

westaust55

Moderator
I dont see the tie with what I was reading in the manual and HOLDTILLHIGH command, I havent encountered this word before.
HoldTillHigh is just a label or reference point.
The IF... THEN command tests for the pin being low (= 0) meaning switch not yet closed and if still low jump back to the HoldTillHigh label and test again. In effect a means of waiting for the pin to go high.
 

westaust55

Moderator
I think I figured out my problem. (noob ;) mistake )
I believe I was using b.0 instead of c.0. But I am away from the project for the week traveling.
I do apologize for the confusion on these posts.
To claify my suspision, using a 14m2- one uses b.0 OR c.o as input and b0 OR c0 as an output. correct?
Please have a read at the following sections of PICAXE manual 2 to clarify the difference between variables (to store values) and IO pin desingations.

Variables - General - see page 10

Input / Output Pin Naming Conventions - see page 27
IO pins generally use the same deignations for input or outpout function on the same pin.
But you may need to use either the DIRSB or DIRSC command to change a pin from the default input direction to an output.
 

Axel87

Senior Member
Well this is what i came up with tonight-

Code:
; ****************************************************************************************************
;    Filename: 	Motorcycle Flasher		
;    Date: 	7/9/2013		
;    Target PICAXE: 14m2
; ****************************************************************************************************


		
init: let b0 = 0			; switch "variable bit" (correct terminology??)
	let b1 = 0			; flasher "Variable bit"


myloop: 						;myloop, pushed- code taken from manual 2 pg.41
	
	button C.0,1,200,100,b2,1,pushed	; jump to cont when C.0 = 1
	low B.7 					; output off
	pause 10					 ; loop delay time
	goto myloop
pushed: 
	inc b0
	if b0=5 then flasher			; if b0=5( for simulation only 2 times actual)
	pause 1000					; For simulation only
	goto myloop
	
flasher: 
	
	if  button C.0 = 1 then inc b1		; if c.0 pressed again(2 more times for simulation), return to myloop
	if b1 = 2 then myloop
	
	endif			; The following pending circuit design- one pin for each bulb or drive F,R off relay??
	high b.5		; LF Turn Signal High
	high b.4		; RF Turn Signal High
	high b.3		; LR Turn Signal High
	high b.2		; RR Turn Signal High
	pause 1000		; for simulation only	
	low b.5 		; LF Turn Signal Low
	low b.4		; RF Turn Signal Low
	low b.3		; LR Turn Signal Low
	low b.2		; RR Turn Signal Low
	pause 1000 		; For Simulation only
	goto flasher

I ran into a an error on the -
if button C.0 = 1 then inc b1 ; if c.0 pressed again(2 more times for simulation), return to myloop

Sure it goes back to my lack of strong grip on labels, but i tried different combinations and couldent get it to work.
Is this alot of code for such a simple process? Am I over thinking it?
Let me know if you have any questions, appreciate any input.

p.s Still on the road so dont have access to the project, using simulation only. I can try to provide a schemo tomorrow night if needed, please check added notes hopefully theyll clear up some confusion ;/.
 

westaust55

Moderator
@Axel87,

From the top of your code we can see it is related to a motor cycle flasher system

But what exactly do YOU want to happen? Different folks will have different ideas on what should be done.

Please write down in plain English as a series of very basic steps what you want to happen to the desired order of events.

We need for example to know if you want anything to happen between each of the 5 switch.button presses.
How close together (5, 10, 15 secdonds or other) are the 5 button presses to be to be recognised as a "command"?
 

Axel87

Senior Member
Think I got rid of the error. How does this look to everyone?

Code:
; ****************************************************************************************************
;    Filename: 	Motorcycle Flasher		
;    Date: 	7/9/2013		
;    Target PICAXE: 14m2
; ****************************************************************************************************


		
init: let b0 = 0			; switch "variable bit" (correct terminology??)
	let b1 = 0			; flasher "Variable bit"


myloop: 						;myloop, pushed- code taken from manual 2 pg.41
	
	button C.0,1,200,100,b2,1,pushed	; jump to cont when C.0 = 1
	low B.7 					; output off
	pause 10					 ; loop delay time
	goto myloop
pushed: 
	inc b0
	if b0=5 then flasher			; if b0=5( for simulation only 2 times actual)
	pause 1000					; For simulation only
	goto myloop
	
flasher: 
	
	if  pinC.0 = 1 then inc b1		; if c.0 pressed again(2 more times for simulation), return to myloop
	if b1 = 2 then myloop
	
	endif			; The following pending circuit design- one pin for each bulb or drive F,R off relay??
	high b.5		; LF Turn Signal High
	high b.4		; RF Turn Signal High
	high b.3		; LR Turn Signal High
	high b.2		; RR Turn Signal High
	pause 1000		; for simulation only	
	low b.5 		; LF Turn Signal Low
	low b.4		; RF Turn Signal Low
	low b.3		; LR Turn Signal Low
	low b.2		; RR Turn Signal Low
	pause 1000 		; For Simulation only
	goto flasher
 

westaust55

Moderator
Guessing in the absence of a clear plain English descrition of what you want the code to do (there is comments such as "(2 more times for simulation)" so not 100% clear what is the final product nor why you would remove the lines PAUSE 1000 in the flasher: routine which will make it flash very rapidly and off time may not be visible. However as a potential comemnt/question:

After you have executed the flasher loop and the lines:

if pinC.0 = 1 then inc b1
if b1 = 2 then myloop

do you need to clear byte variable b1 on return to myloop ready for the next occasion?
 

bfgstew

Senior Member
Think he does Westy, as it just sits there counting in a loop until the byte variable overflows............:rolleyes:

A clear and concise description of how you want this code to perform and what it is you actually want it to do would help no end!
 

Axel87

Senior Member
@Axel87,

From the top of your code we can see it is related to a motor cycle flasher system

But what exactly do YOU want to happen? Different folks will have different ideas on what should be done.

Please write down in plain English as a series of very basic steps what you want to happen to the desired order of events.

We need for example to know if you want anything to happen between each of the 5 switch.button presses.
How close together (5, 10, 15 secdonds or other) are the 5 button presses to be to be recognised as a "command"?
I apologize for the lack of required details, as you had said, it may be obvious to me but not to others.
What Im looking to do is use the horn switch, NO. to activate the flasher routine.
Lets say 5 pushes of the switch in 10 sec of eachother.
once in the flash program ( let say 2 loops through) another push of the button will bring it back to the main loop.
Again thank you for your patience and assistance, let me know if i am forgetting any details.
 

bfgstew

Senior Member
Try this version, in simulation press the C.1 tab to simulate the horn push, this inc b0 until it reaches 5 goes to the flasher routine inc b1 until it reaches 2, loops back to init to reset everything.

Code:
init: let b0 = 0			; switch "variable bit" (correct terminology??)
	let b1 = 0			; flasher "Variable bit"


myloop: 					
	do
	pause 500
 	if pinC.1 = 1 then 
 	inc b0 
 	endif
      if b0=5 then goto flasher 
      loop

	
flasher: 
	
	if b1 = 2 then init
	high b.5		; LF Turn Signal High
	high b.4		; RF Turn Signal High
	high b.3		; LR Turn Signal High
	high b.2		; RR Turn Signal High
	pause 1000		; for simulation only	
	low b.5 		; LF Turn Signal Low
	low b.4		; RF Turn Signal Low
	low b.3		; LR Turn Signal Low
	low b.2		; RR Turn Signal Low
	pause 1000
	inc b1 		; For Simulation only
	goto flasher
 

Hemi345

Senior Member
I haven't got a clear understanding if you're driving LEDs or relays or what with pins B.2, B.3, B.4 and B.5... but remember the PICAXE "can sink or
source 20ma on each output pin, maximum 90mA per chip". Four LEDS (or whatever) at potentially 25mA each, = 100ma, 10mA over the maximum.
 

Axel87

Senior Member
What I have at the moment at home in the breadboard is a TIP120? driving a 12V relay. the picaxe just triggers the relay. (although I havent done the research as how much this draws. But I assume its under because it works ;))
As I havent gotten the circuit designed quiet yet, I dont know if I will need just one pin or four. But thats what I have thus far.
I did plug in the code provided, and unless I have my simulation speed set wrong, its not quite right.
It seems to only count 5 "loops" through with pin high. This unfortunalty wont work.
I need it to actually count the open/close of the switch.
but other than that issue its getting closer! Thanks!
Any ideas, clues were to go?
comments, questions?
 

Axel87

Senior Member
Try this version, in simulation press the C.1 tab to simulate the horn push, this inc b0 until it reaches 5 goes to the flasher routine inc b1 until it reaches 2, loops back to init to reset everything.

Code:
init: let b0 = 0			; switch "variable bit" (correct terminology??)
	let b1 = 0			; flasher "Variable bit"


myloop: 					
	do
	pause 500
 	if pinC.1 = 1 then 
 	inc b0 
 	endif
      if b0=5 then goto flasher 
      loop

	
flasher: 
	
	if b1 = 2 then init
	high b.5		; LF Turn Signal High
	high b.4		; RF Turn Signal High
	high b.3		; LR Turn Signal High
	high b.2		; RR Turn Signal High
	pause 1000		; for simulation only	
	low b.5 		; LF Turn Signal Low
	low b.4		; RF Turn Signal Low
	low b.3		; LR Turn Signal Low
	low b.2		; RR Turn Signal Low
	pause 1000
	inc b1 		; For Simulation only
	goto flasher
This would work, but I will possibly use this train of thought for other projects. For this, Im looking for an open/close x 5 reading.
Thanks again for the input!
 

Hemi345

Senior Member
This is probably how I would do it if I understand your requirements right in post #29 (although I didn't put in a check for your 5 button presses in 10 seconds... easy enough to add using something like the 'time' command in the main routine)

Code:
setint %00000010,%00000010 ;arm interrupt for high on pin C.1

init:
    let b0 = 0 ;switch counter byte
    gosub allLow ;make sure the turn signals are all off

main:
    if b0 = 5 then flasher
    goto main

flasher: 
	high b.5		; LF Turn Signal High 
	high b.4		; RF Turn Signal High 
	high b.3		; LR Turn Signal High 
	high b.2		; RR Turn Signal High 
	if b0 = 6 then init ;check counter byte for 6th button press, if so, exit to init without having to wait for the 1 second pause below
	pause 1000		; for simulation only
	gosub allLow	; put all turn signals low ^
	if b0 = 6 then init ;this here again so, on 6th button press, user will see immediate exit to init without having to wait for the 1 second pause below
	pause 1000
	goto flasher
	
allLow:
	low b.5 		; LF Turn Signal Low
	low b.4		; RF Turn Signal Low
	low b.3		; LR Turn Signal Low
	low b.2		; RR Turn Signal Low
	return

interrupt:
     if pinC.1 = 1 then 
          goto interrupt ;debounce switch
     elseif b0 < 6 then
          inc b0  ;increment variable b0
     endif
     pause 100
     setint %00000010,%00000010 ;re-arm interrupt for high on pin C.1
     return
 

Axel87

Senior Member
wow!
This look promising for sure, but Ive little comprehension as to what is going on in this coding though.
It does seem to work, 5 pulses and it switches the program, but I havent figured out why this works.
Reading up on the different commands you through at me right now. I am sure I will have more questions.
The manual seems too vague on some of these commands, I tried to add a sertxd to watch b.0 and pinc.1 values but havent got it to work yet.
If you have any other materials I could reference to get a better grasp on these, would be grateful!
ie. interrupts, sub routines, setint( I gather this "arms" the subroutine)
Alot to soak in but Ill try my best! Thanks
 

Axel87

Senior Member
This is probably how I would do it if I understand your requirements right in post #29 (although I didn't put in a check for your 5 button presses in 10 seconds... easy enough to add using something like the 'time' command in the main routine)

Code:
setint %00000010,%00000010 ;arm interrupt for high on pin C.1

init:
    let b0 = 0 ;switch counter byte
    gosub allLow ;make sure the turn signals are all off

main:
    if b0 = 5 then flasher
    goto main

flasher: 
	high b.5		; LF Turn Signal High 
	high b.4		; RF Turn Signal High 
	high b.3		; LR Turn Signal High 
	high b.2		; RR Turn Signal High 
	if b0 = 6 then init ;check counter byte for 6th button press, if so, exit to init without having to wait for the 1 second pause below
	pause 1000		; for simulation only
	gosub allLow	; put all turn signals low ^
	if b0 = 6 then init ;this here again so, on 6th button press, user will see immediate exit to init without having to wait for the 1 second pause below
	pause 1000
	goto flasher
	
allLow:
	low b.5 		; LF Turn Signal Low
	low b.4		; RF Turn Signal Low
	low b.3		; LR Turn Signal Low
	low b.2		; RR Turn Signal Low
	return

interrupt:
     if pinC.1 = 1 then 
          goto interrupt ;debounce switch
     elseif b0 < 6 then
          inc b0  ;increment variable b0
     endif
     pause 100
     setint %00000010,%00000010 ;re-arm interrupt for high on pin C.1
     return
Am I even headed down the right path?? Trying to add a count on/off in a set time then do flash.
Code:
setint %00000010,%00000010 ;arm interrupt for high on pin C.1

init:
    let b0 = 0 ;switch counter byte
    gosub allLow ;make sure the turn signals are all off

main:
    if b0 = 5 then flasher
    goto main

flasher: 
	high b.5		; LF Turn Signal High 
	high b.4		; RF Turn Signal High 
	high b.3		; LR Turn Signal High 
	high b.2		; RR Turn Signal High 
	if b0 = 6 then init ;check counter byte for 6th button press, if so, exit to init without having to wait for the 1 second pause below
	pause 1000		; for simulation only
	gosub allLow	; put all turn signals low ^
	if b0 = 6 then init ;this here again so, on 6th button press, user will see immediate exit to init without having to wait for the 1 second pause below
	pause 1000
	goto flasher
	
allLow:
	low b.5 		; LF Turn Signal Low
	low b.4		; RF Turn Signal Low
	low b.3		; LR Turn Signal Low
	low b.2		; RR Turn Signal Low
	return

interrupt:
     
     if pinC.1 = 1 then 
          goto interrupt ;debounce switch
     elseif pinC.1 = 0 then endif 
     do if pinc.1=1 then wait 1
     if pinc.1=0 then inc b0 endif
     loop
     elseif b0 =5 then goto flasher 
     elseif b0=>1 then
          goto init:
     endif
     setint %00000010,%00000010 ;re-arm interrupt for high on pin C.1
     return
 

Axel87

Senior Member
By golly I think I may have gotten it!! lol

Code:
setint %00000010,%00000010 ;arm interrupt for high on pin C.1

init:
    let b0 = 0 ;switch counter byte
    gosub allLow ;make sure the turn signals are all off

main:
    if b0 = 5 then flasher
    goto main

flasher: 
	high b.5		; LF Turn Signal High 
	high b.4		; RF Turn Signal High 
	high b.3		; LR Turn Signal High 
	high b.2		; RR Turn Signal High 
	if b0 = 6 then init ;check counter byte for 6th button press, if so, exit to init without having to wait for the 1 second pause below
	pause 1000		; for simulation only
	gosub allLow	; put all turn signals low ^
	if b0 = 6 then init ;this here again so, on 6th button press, user will see immediate exit to init without having to wait for the 1 second pause below
	pause 1000
	goto flasher
	
allLow:
	low b.5 		; LF Turn Signal Low
	low b.4		; RF Turn Signal Low
	low b.3		; LR Turn Signal Low
	low b.2		; RR Turn Signal Low
	return

interrupt:
     
     if pinC.1 = 1 then 
          goto interrupt ;debounce switch
     elseif pinC.1 = 0 then endif
     do if pinc.1=0 then inc b0 
     elseif b0 =5 then goto flasher 
     if b0=>1 then
          goto init:
          loop
     endif
     endif
     setint %00000010,%00000010 ;re-arm interrupt for high on pin C.1
     return
Also, Ive realized this code has morphed from the original post and I apologize to anyone confused by the label.
Originally I was going to use post as a LED STRIP controller, but i got sidetracked. (This tends to happen to me alot ;))
Hope you guys/gals can take a look and see if you have any concerns with the code.
I will plan on making a new forum, mark complete and provide code and a schemo for it when finished. Hopefully I wont run into many bumbs along the way.
But I wont get ahead of myself here, does anyone see any issues with this code? A more productive way to acomplish this?
Thanks!
BTW hats off to Hemi345 for the provided code, and of course everyone else. I cant say I knew what I was doing when modifying his code, just taking wild guesses ;/. Hopefully get a little more explanation on the hows/whys when someone has time :)
 

westaust55

Moderator
What Im looking to do is use the horn switch, NO. to activate the flasher routine.
Lets say 5 pushes of the switch in 10 sec of eachother.
once in the flash program ( let say 2 loops through) another push of the button will bring it back to the main loop.
While the BUTTON command is working for you along with incrementing of a variable, another option may be to consider the COUNT command.
If you scan for the first input pulse with the IF ... THEN line and when detected use the COUNT command to check for >= 4 more pulses in the desired 10 second time frame then you only need to check the results of count are > = 4 and proceed to flasher is so else return to start.
You may ultimately also want a small value capacitor on the input line to the PICAXE to help filter out contact bounce.
 
Top