Little Vid and Pic of LED array

Shafto

Senior Member
Well.. I must say this little device is pretty cool. I hooked it all up and it worked first try! first I just lit the LEDs sequentially with a pause 60, then I hooked up the 2 pots and added the adjustability of how fast the array fills and how fast it goes out.. I can't believe the ease in which I did this, I thought the coding was gonna be the hardest part.. so far the hardest part was getting all the parts!

Big thanks to everyone here for the help I've received so far, just wanted to show you that I'm doing something with it! Now I'll just make it so a digital input receives the blinker pulse from the car and make that trigger the sequence..

I'll rig that up here to get a feel for it with a switch to mimic the signal pulse.. and then I gotta try the PWM for the brakes.. and then rig up both sides of the signal and make sure only the side that's supposed to be signaling has power... it's all coming together now and I'm stoked.

Here's the simple little program I wrote:

Code:
main: 

	readadc 0,b0

	readadc 1,b1

	high 0

	pause b0

	high 1

	pause b0

	high 2

	pause b0

	high 3

	pause b0

	high 4
	
	pause b0

	high 5

	pause b0

	high 6

	pause b0

	high 7

	pause b1

	low 7

	pause b1

	low 6

	pause b1

	low 5

	pause b1

	low 4

	pause b1

	low 3

	pause b1

	low 2

	pause b1

	low 1

	pause b1

	low 0

	pause b1

	pause 50

	goto main


Can't get video to load into photobucket.. I'll get a youtube account here or something so I can upload it.

edit: I dunno why the code tags don't work, what am I missing?

edit 2: Here's the vid.. although I'm pretty much ready to make another.. I've got much more done now.
http://www.youtube.com/watch?v=BXMnO5fFuxc
 
Last edited:

Shafto

Senior Member
Thanks!

I just expanded the program and circuit a bit, there's now 2 rows of 8 LEDs on a seperate project board for left and right flashers... I imagine there's probably a neater more condensed way to achieve this.. I don't think I need to write out the whole sequence twice? I'm not sure how to do it any other way yet though.. if there isn't a better way I'll have to write out the sequence one more for high pin0 and high pin1 for the hazard lights... but it's working as I want.. this is really cool!

Now I just need to setup the PWM for the marker function of the brake lights.. I'm not sure how to tie the duty cycle of the PWM output to a pot though.. I'm combing through the manuals right now...

Please if you have any suggestions on how to make the program better I'd love to hear it!

I can't believe how quickly it's all coming together.

Code:
main:

	if pin0 = 1 then flashleft

	if pin1 = 1 then flashright

	if pin0 = 0 and pin1 = 0 then main

flashleft:

	high portc 7

	readadc 0,b0

	readadc 1,b1

	high 0

	pause b0

	high 1

	pause b0

	high 2

	pause b0

	high 3

	pause b0

	high 4
	
	pause b0

	high 5

	pause b0

	high 6

	pause b0

	high 7

	pause b1

	low 7

	pause b1

	low 6

	pause b1

	low 5

	pause b1

	low 4

	pause b1

	low 3

	pause b1

	low 2

	pause b1

	low 1

	pause b1

	low 0

	pause b1

	pause 50

	low portc 7

	goto main

flashright:

	high portc 6

	readadc 0,b0

	readadc 1,b1

	high 0

	pause b0

	high 1

	pause b0

	high 2

	pause b0

	high 3

	pause b0

	high 4
	
	pause b0

	high 5

	pause b0

	high 6

	pause b0

	high 7

	pause b1

	low 7

	pause b1

	low 6

	pause b1

	low 5

	pause b1

	low 4

	pause b1

	low 3

	pause b1

	low 2

	pause b1

	low 1

	pause b1

	low 0

	pause b1

	pause 50

	low portc 6

	goto main
 
Last edited:

Shafto

Senior Member
Video added.

I've got the PWM going now.. I just used:

pwmout 2,150,b2

but I've got a little problem.

now b3 only goes to 255, and the PWM duty goes up to 1023, so I tried to just put:

pwmout 2,150,b2*4 but that doesn't work.. I thought you could do math? I'm not sure.. I then looked into making a word variable by setting b3 to the analogue input, then let b2 = 4 and I put:

pwmout 2,150,w1 ..but it just acts all erratic.. I'm sure I have to set how I want to word variable to calculate, whether it's * or / but I can't figure this out.. there are no examples for this in the manuals.. examples really help.

Edit: I ended up just using the PWM wizard and found that a period of 63 makes the 0-255 value of B2 take the PWM from ~0~100% and works quite well.. but I'd still like to know how to incorporate math into what I'm doing.
 
Last edited:

Matt_C

Member
Try this

Hi

This is my first post so I hope it works and can help.

Code:
symbol	upspeed		= w0
symbol	downspeed	= w1
symbol	counter		= b4
symbol	led		= b5
symbol	temp		= b6
symbol	way		= b7

symbol	left		= 7
symbol	right		= 6

main:
	if pin0 = 1 then
		way = left
		gosub ramplights
	endif
	if pin1 = 1 then
		way = right
		gosub ramplights
	endif
	goto main
	
ramplights:
	gosub readspeed
	high portc way
	for counter = 0 to 1
		for led = 0 to 7
			if counter = 0 then
				high led
				pause upspeed
			else
				temp = 7 - led
				low temp
				pause downspeed
			endif
		next led
	next counter
	low portc way
	return
	
readspeed:
	readadc10 0,upspeed
	readadc10 1,downspeed
	return
The readadc10 command should get over your 256 limitation when you sample the speed pot as it returns a 10 bit answer over the standard 8 bit.
Your original code worked out at 147 bytes but my version works out at 81 bytes.
I'm just starting out myself with PICAXE and I think it's great but I'm sure my version can be improved on.
I have had a few years programming experience so I guess that helps.

Let us know how you get on and if this version helps.

Good luck.

Matt.
 
Last edited:

SD2100

New Member
Here's a 62 byte version, maybe someone can squeeze it under 50 :)

Code:
symbol Loop1 = b2

main:
    low portc 6
    low portc 7
    if pin0 = 1 then 'flashleft
        high portc 7
        goto flash
    elseif pin1 = 1 then 'flashright
        high portc 6
        goto flash
    end if
    goto main
		
Flash:
    readadc 0,b0
    readadc 1,b1
	
    for Loop1 = 0 to 7
        high Loop1
        pause b0
    next Loop1
	
    for Loop1 = 7 to 0 step -1
        pause b1
        low Loop1
    next Loop1
    
        pause b1
        pause 50
        
        goto main
Have you ever tried to use something like this on PORTC
Code:
LOW PORTC 6, 7
7 turns ON !!!
 
Last edited:

Matt_C

Member
Very nice.

I got it down to 59 bytes by replacing
Code:
low portc 6
low portc 7
With

Code:
portc = 0
 

Matt_C

Member
Got it down to 50 bytes now.

Code:
symbol Loop1 = b2

main:
	portc = 0
	branch pins,(main,flash,flash)
	
Flash:
	b3 = pins ^ 3 + 5
	high portc b3
	readadc 0,b0
	readadc 1,b1
	for Loop1 = 0 to 7
		high Loop1
		pause b0
	next Loop1
	for Loop1 = 7 to 0 step -1
		pause b1
		low Loop1
	next Loop1
	pause b1
	pause 50
	goto main
 

Shafto

Senior Member
Thanks for the suggestions, unfortunately it didn't work for me... I dunno what's up... here's my program now.. now that I've expanded it

Code:
main:
	readadc 0,b0

	readadc 1,b1

	readadc 2,b2

	pwmout 2,63,b2

	if pin0 = 1 and pin1 = 1 then flashhazard

	if pin0 = 1 then flashleft

	if pin1 = 1 then flashright

	if pin0 = 0 and pin1 = 0 then main

flashleft:

	high portc 7

	high 0

	pause b0

	high 1

	pause b0

	high 2

	pause b0

	high 3

	pause b0

	high 4
	
	pause b0

	high 5

	pause b0

	high 6

	pause b0

	high 7

	pause b1

	low 7

	pause b1

	low 6

	pause b1

	low 5

	pause b1

	low 4

	pause b1

	low 3

	pause b1

	low 2

	pause b1

	low 1

	pause b1

	low 0

	pause b1

	pause 50

	low portc 7

	goto main

flashright:

	high portc 6

	high 0

	pause b0

	high 1

	pause b0

	high 2

	pause b0

	high 3

	pause b0

	high 4
	
	pause b0

	high 5

	pause b0

	high 6

	pause b0

	high 7

	pause b1

	low 7

	pause b1

	low 6

	pause b1

	low 5

	pause b1

	low 4

	pause b1

	low 3

	pause b1

	low 2

	pause b1

	low 1

	pause b1

	low 0

	pause b1

	pause 50

	low portc 6

	goto main

flashhazard:

	high portc 7

	high portc 6

	high 0

	pause b0

	high 1

	pause b0

	high 2

	pause b0

	high 3

	pause b0

	high 4
	
	pause b0

	high 5

	pause b0

	high 6

	pause b0

	high 7

	pause b1

	low 7

	pause b1

	low 6

	pause b1

	low 5

	pause b1

	low 4

	pause b1

	low 3

	pause b1

	low 2

	pause b1

	low 1

	pause b1

	low 0

	pause b1

	pause 50

	low portc 7

	low portc 6

	goto main
I tried to add this in for the left flasher to try it:

Code:
symbol loop1 = b3

main:
	
	low portc 6

	low portc 7

	readadc 0,b0

	readadc 1,b1

	readadc 2,b2

	pwmout 2,63,b2

	if pin0 = 1 and pin1 = 1 then flashhazard

	if pin0 = 1 then flashleft

	if pin1 = 1 then flashright

	if pin0 = 0 and pin1 = 0 then main

flashleft:

	for loop1 = 0 to 7

	high loop1

	pause b0

	next loop1

	for loop1 = 7 to 0 step -1

	pause b1

	low loop1

	next loop1

flashright:

	high portc 6

	high 0

	pause b0

	high 1

	pause b0

	high 2

	pause b0

	high 3

	pause b0

	high 4
	
	pause b0

	high 5

	pause b0

	high 6

	pause b0

	high 7

	pause b1

	low 7

	pause b1

	low 6

	pause b1

	low 5

	pause b1

	low 4

	pause b1

	low 3

	pause b1

	low 2

	pause b1

	low 1

	pause b1

	low 0

	pause b1

	pause 50

	goto main

flashhazard:

	high portc 7

	high portc 6

	high 0

	pause b0

	high 1

	pause b0

	high 2

	pause b0

	high 3

	pause b0

	high 4
	
	pause b0

	high 5

	pause b0

	high 6

	pause b0

	high 7

	pause b1

	low 7

	pause b1

	low 6

	pause b1

	low 5

	pause b1

	low 4

	pause b1

	low 3

	pause b1

	low 2

	pause b1

	low 1

	pause b1

	low 0

	pause b1

	pause 50

	goto main
I don't fully understand how that works.. I was pretty much just copying it over, so I dunno.. I probably didn't adapt it properly.. I get weird operation though.. it won't flash left, and after I let go of the left flash button it will flash right.. weird.
 

Rickharris

Senior Member
Video added.

I've got the PWM going now.. I just used:

pwmout 2,150,b2

but I've got a little problem.

now b3 only goes to 255, and the PWM duty goes up to 1023, so I tried to just put:

pwmout 2,150,b2*4 but that doesn't work.. I thought you could do math? I'm not sure.. I then looked into making a word variable by setting b3 to the analogue input, then let b2 = 4 and I put:

pwmout 2,150,w1 ..but it just acts all erratic.. I'm sure I have to set how I want to word variable to calculate, whether it's * or / but I can't figure this out.. there are no examples for this in the manuals.. examples really help.

Edit: I ended up just using the PWM wizard and found that a period of 63 makes the 0-255 value of B2 take the PWM from ~0~100% and works quite well.. but I'd still like to know how to incorporate math into what I'm doing.

You are almost right - A byte variable B0 - B1 etc can only be used to count up to 255 (there are only 8 binary bits in a byte and 8 bits = 255)

A word uses 16 bits so can count to 65335 BUT not that W0 is made from B0 and B1 put together W1 is made from B2 and B3 put together etc. See page 9 of the basic commands PDF.

Using these byte variables elsewhere in your programme may cause odd things to happen.
 

Matt_C

Member
Try this -

Code:
symbol Loop1 = b3

main:
	low portc 7
	low portc 6
	
	readadc 0,b0
	readadc 1,b1
	readadc 2,b2

	pwmout 2,63,b2
	
	if pins > 0 then flash
	
	goto main
	
Flash:
	select pins
		case 1	'leftflash
			high portc 7
		case 2	'lrightflash
			high portc 6
		case 3	'hazardflash
			high portc 7
			high portc 6
	endselect
	for Loop1 = 0 to 7
		high Loop1
		pause b0
	next Loop1
	for Loop1 = 7 to 0 step -1
		pause b1
		low Loop1
	next Loop1
	pause b1
	pause 50
	goto main
 

Shafto

Senior Member
I'm using a 28x1,

This time it worked! however there's a slight issue.. for some reason there is a delay from from the input to when the signal fires.. about half a second, there is no delay with my code, even though it's longer... weird.
 

Shack

Member
I'm using a 28x1,

This time it worked! however there's a slight issue.. for some reason there is a delay from from the input to when the signal fires.. about half a second, there is no delay with my code, even though it's longer... weird.
This is really neat. Please post the best working code as completed.

I think I would like to make one of these for a go-cart application to use as turn signals!

If I had two buttons on the wheel can I trigger either side>

Post your schematic as well if possible.
 

Shafto

Senior Member
sure thing! I'd love to help out.

After I design the PCBs on my computer I'll have schematics to post.

This is my first time at doing anything like this, so far it's turning out great and I'm loving it.
 
Top