Day 3 - when 1 led is just not enough - how about 8 leds....
by, 06-03-2012 at 21:53 (1063 Views)
This was an interesting challenge. i can do 8 leds when all on the same port but the shield base has 2 ports down the traditional arduino digital ports. So what to do? the first program is easy - just program them all individually. great but what if i want to change things?
Enter the forum and the master coder hippy.
here is a link to my forum post and my question is below:
so here it goes - day three and 8 leds directly driven by the shield base.sequencing leds on picaxe sheild base s.2 to s.9
just in the process of converting the sparkfun inventor's kit from arduino to picaxe. Which has been an interesting and enjoyable challenge but I must now return to an aspect that I cannot find a solution for, cascading LEDs from s.2 to s.9 and back again. The arduino uses an array to move from 2 to 3 etc. This would be easy if the shield outputs were all from the same port and in sequential order but they are not.
a simple shield base solution would be to:
A simple 28x2 solution would be to:Code:'LEDs connected to s.2 to s.9 of the shield base #sim axe401 #picaxe 28x2 #no_table do high s.2 pause 500 low s.2 high s.3 pause 500 low s.3 high s.4 pause 500 low s.4 high s.5 pause 500 low s.5 high s.6 pause 500 low s.6 high s.7 pause 500 low s.7 high s.8 pause 500 low s.8 high s.9 pause 500 low s.9 loop
I want to do the second one of the shield base without complicating the wiring up (or changing it from the first example from above)Code:#sim none #picaxe 28x2 #no-table b0 = 1 dirsB = %11111111 do pinsB = b0 if b0 = 128 then '%10000000 for binary or $80 for hex b0 = 1 '%00000001 for binary or $01 for hex reset the led to the first one else b0 = b0 * 2 'set the next led on - see binary maths in the manual 1 for help end if pause 500 loop
the next step would be to 'knight rider' it but don't want to individually code each LED.
Thought of a lookup table or using the scratch pad to store the binary sequence of the s.[pins] output but would need to change between the B and C ports.
the sequence would look like:
s.2 - pinsB = %00000100 or $04 or 4
s.3 - pinsB = %00000001 or $01 or 1
s.4 - pinsB = %00000010 or $02 or 2
s.5 - pinsB = %00100000 or $20 or 32
s.6 - pinsB = %01000000 or $40 or 64
s.7 - pinsB = %10000000 or $80 or 128
s.8 - pinsC = %00000001 or $01 or 1
s.9 - pinsC = %00000010 or $02 or 2
how do i change from pinsB to pinsC without making it too complecated - remeber this is activity 2 on an introductory set of activities. I don't mind introducing lookup tables or memory pointers as this is an extention activity but if i need to have too many complicated decision statements it will turn th euser off, especially when moving to the knight rider style of example.
Can anyone help?
thanks in advance - if there is no suitable solution I will leave it out - contemplated it already but thought I would give it to the great minds of the forum.
the 3d exploded diagram is below:
the breadboard overlay.
There is still more to come but i haven't had much time so wanted to get this out