40X2 doesn't seem to work as planned ???

SolidWorksMagi

Senior Member
Hi,

Here's the code ... if you can test it on your system and see if it works for you I'd like to know ... it's screwing up for me and I don't know why ... the 40X2 is connected to the AXE091 Development board

; 40X2-3-Color-LED-Tests.bas

#picaxe 40X2

; 3-Color LED1 PINs = B.7 red, B.6 green, B.5 blue
; 3-Color LED2 PINs = A.7 red, A.6 green, A.5 blue
; 3-Color LED1 PINs = D.7 red, D.6 green, D.5 blue

; 76543210
; RGB
dirsb = %11100000 ; make B.7 to B.5 outputs
dirsd = %11100000 ; make D.7 to D.5 outputs
dirsa = %11100000 ; make A.7 to A.5 outputs
; RGB+hserout
dirsc = %11110000 ; make C.7 to C.4 outputs

hsersetup B9600_8, %00000 ; 9600 baud, non-inverted polarity

symbol i = b0

; BEGIN Main Body * * * * * * * * * * * * * * * * * * * * * * *
gosub LEDsOFF
pause 1000

do
;gosub RGB1
;gosub RGB2
;gosub RGB3
gosub RGBA

gosub LEDsOFF
pause 1000
loop
; END Main Body * * * * * * * * * * * * * * * * * * * * * * **
end
; BEGIN LED subroutines * * * * * * * * * * * * * * *
RGB1:
gosub redLED1
pause 500
gosub greenLED1
pause 500
gosub blueLED1
pause 500
return

RGB2:
gosub redLED2
pause 500
gosub greenLED2
pause 500
gosub blueLED2
pause 500
return

RGB3:
gosub redLED3
pause 500
gosub greenLED3
pause 500
gosub blueLED3
pause 500
return

RGBA:
gosub redLED1
gosub greenLED2
gosub blueLED3
pause 500
gosub greenLED1
gosub blueLED2
gosub redLED3
pause 500
gosub blueLED1
gosub redLED2
gosub greenLED3
pause 500
return

LEDsOFF:
; 76543210
let pinsb = %11111100 ; OFF
let pinsd = %11100000 ; OFF
let pinsa = %11100000 ; OFF
return

redLED1:
; redLED1 RGB
let pinsb = %01111100 ; RED LED1
return

greenLED1:
; greenLED1 RGB
let pinsb = %10111100 ; GREEN LED1
return

blueLED1:
; blueLED1 RGB
let pinsb = %11011100 ; BLUE LED1
return


redLED2:
; redLED2 RGB
let pinsa = %01111111 ; RED LED2
return

greenLED2:
; greenLED2 RGB
let pinsa = %10111111 ; GREEN LED2
return

blueLED2:
; blueLED2 RGB
let pinsa = %11011111 ; BLUE LED2
return


redLED3:
; redLED3 RGB
let pinsd = %01111100 ; RED LED3
return

greenLED3:
; greenLED3 RGB
let pinsd = %10111100 ; GREEN LED3
return

blueLED3:
; blueLED3 RGB
let pinsd = %11011100 ; BLUE LED3
return

end
 
Last edited:

inglewoodpete

Senior Member
Forum members will willingly help you to solve your problems but it can be a bit much to expect them to load and debug your code.

Just scanning the first few lines of your code indicates that the directions on the pins on Port A (LED2) do not match your spec.

My suggestion is to start small and learn and then build your code as you have success. And please, please include lots of comments!

Try the following to test the basic principles of changing the colours on just one LED:
Code:
[color=Green]; 40X2-3-Color-LED-Tests.bas[/color]

[color=Navy]#picaxe [/color][color=Black]40X2[/color]

[color=Green]; 3-Color LED1 PINs = B.7 red, B.6 green, B.5 blue

; 76543210
; RGB[/color]
[color=Purple]dirsb [/color][color=DarkCyan]= [/color][color=Navy]%11100000          [/color][color=Green]; make B.7 to B.5 outputs[/color]

[color=Blue]symbol [/color][color=Purple]bOutVal [/color][color=DarkCyan]= [/color][color=Purple]b10[/color]

[color=Green]; BEGIN Main Body * * * * * * * * * * * * * * * * * * * * * * *[/color]
[color=Blue]do
   [/color][color=Purple]pinsb [/color][color=DarkCyan]= [/color][color=Purple]bOutVal         [/color][color=Green]; Set colours to new value
   [/color][color=Blue]pause [/color][color=Navy]500
   [/color][color=Purple]bOutVal [/color][color=DarkCyan]= [/color][color=Purple]bOutVal [/color][color=DarkCyan]+ [/color][color=Navy]32  [/color][color=Green]; Step to next colour combination[/color]
[color=Blue]loop[/color]
[color=Green]; END Main Body * * * * * * * * * * * * * * * * * * * * * * **[/color]
 

SolidWorksMagi

Senior Member
Hi,

PINs 7, 6 and 5 on pinsa are %76500000 ... how does that not match? turning ON 7, 6 and 5 works individually, but not with the RGBA subroutine.
 

inglewoodpete

Senior Member
Your specification for LED2:
Code:
 [color=Green]; 3-Color LED1 PINs = B.7 red, B.6 green, B.5 blue
 ; 3-Color LED2 PINs = A.0 red, A.1 green, A.2 blue
 ; 3-Color LED1 PINs = D.7 red, D.6 green, D.5 blue[/color]
From what you're saying, the LEDs work with different code but not with the code you posted. Can you post the code that does work? Please code markers as described here.
 

cravenhaven

Senior Member
Ran it on the picaxe simulator and it all looks fine as best I can tell.
I assume by your subroutine labels that you have the LEDs wired to Vcc from the individual pins, so that when you set the pins high the LEDs turn off.
What does it do wrong?. What is it supposed to do?.
 

SolidWorksMagi

Senior Member
Hi,

Yes, the program runs. I'm using common anode 3-color LEDs ... turning them on one at a time they look good, but when using the RGBA subroutine the blue LEDs are so dim you can't seem them!

RGBA:
gosub redLED1
gosub greenLED2
gosub blueLED3
pause 500
gosub greenLED1
gosub blueLED2
gosub redLED3
pause 500
gosub blueLED1
gosub redLED2
gosub greenLED3
pause 500
return

With the LEDs powered from an external 5V source I would think they'd be working better than what I'm getting.
 

AllyCat

Senior Member
Hi,

What value series resistor(s) are you using for the three LEDs?

Note that three separate resistors are required (if more than one LED is to be active at any time) because the forward voltage drop of a blue LED is usually far higher than a red LED (with Green somewhere inbetween).

Cheers, Alan.
 

inglewoodpete

Senior Member
Hi,

Yes, the program runs. I'm using common anode 3-color LEDs ... turning them on one at a time they look good, but when using the RGBA subroutine the blue LEDs are so dim you can't seem them!

With the LEDs powered from an external 5V source I would think they'd be working better than what I'm getting.
If you had taken the time to load and run the code I provided in post #3, it would have shown that the problem was not in code but a hardware design issue.
 

SolidWorksMagi

Senior Member
Hi,

That is the problem. I was sharing one 220 resistor ... now I have four 220 resistors on the bread board and no room for my synth chip!

Thanks!
 
Top