Rgb buttons code

i'm working on an rgb button grid ( the sparkfun one ) and i can't figure out a neat way to make my code. The situation is that i'm using arduino dual core ( in the exibition ) but thats besides the point, if i can just get half the board working, together other half can work fine as well.

The only idea i get is that i make delays, and inbetween delays i change the ground pin, and make color changes through pwm. Id there a pwm friendly way tio setup a grid where i can have alot of room to work with and add code and such?

A.squars code is WAY too complicated. I don't know how he achieved the outcome, but he did it very well! if i understood his code, i might be able to work with it, but i can bairly understand anything in his code!

thanks for any help!

What are you trying to do as far as triggering the LED’s?

Serial, the actual buttons on the interface, etc.

Depending on how you want theLED’s to act with certain actions the code will change.

for now they are just lights on buttons, once i get the lights working, ill get the actual button part working.

so here is my first try at a code for this:

void setup(){
pinMode(2, OUTPUT);
pinMode(4, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
}
void loop()
{

delay(10);
digitalWrite(2, LOW);

analogWrite(3, 255);

delay(10);
analogWrite(3, 0);
digitalWrite(2, HIGH);
digitalWrite(4, LOW);

delay(10);

digitalWrite(4, HIGH);
digitalWrite(7, LOW);

delay(10);

digitalWrite(7, HIGH);
digitalWrite(8, LOW);

delay(10);

digitalWrite(8, HIGH);
}

i put delay(10) becuase i wanted to debug, becuase when i set it to 1, it's sapposed to just turn one light on, but it looks like it" bleeds" off to the next two buttons, for no particular reason. do you know why it runs on to the other lights?

Well first off, you're referring to AnalogWrite(3, 255) twice, And you didn't specify pin 3, so that's one problem.

Also, try setting the delay to something like 300 so that you have 3 seconds to confirm that they're being written to.

I don't understand what you mean by "bleeds off" but I'm assuming that the lights flash past sofast that your eyes don't notice

So fix the nonexistent pin(or do you not need to specify for analogwrite?)

And set the delays to 300(3 seconds) so you can see the individual changes.

sorry, i meant by “bleed off” that it doesent stay on one buttons, when i set delay 1 one, so it’s faster then the human eye can see, it can be seen on 3 buttons, when it’s only sapposed to be seen on one. Is it maybe arduino that’s incapable of operating that fast? also on 2 of the 3 buttons where you can see the light on, there is a dimming affect, and the other button has the opposite, and then a middle button just stay constantly on.

my code try’s to turn rows of ground wires off and on so that i can light each individual lights. Thats why you see me delaying by one, then switching 2 digital output’s. and then where there is one digital output, i putt in a pwm for full on, and turn it off in the next delay, so it turns on for one button.

do you understand the problem and my code? i’m kind of new to writing codes, so i can only write codes that are basic…

here is the new code which does the exact same thing, but i set the pwm pins as outputs like it sais to do in the reference, but it still does the same thing…

int delay1 = 1;

void setup(){
pinMode(2, OUTPUT);
pinMode(4, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(11, OUTPUT);
pinMode(10, OUTPUT);
pinMode(9, OUTPUT);
pinMode(6, OUTPUT);
pinMode(5, OUTPUT);
pinMode(3, OUTPUT);
}
void loop()
{

delay(delay1);
digitalWrite(2, LOW);

analogWrite(3, 255);

delay(delay1);
analogWrite(3, 0);
digitalWrite(2, HIGH);
digitalWrite(4, LOW);

delay(delay1);

digitalWrite(4, HIGH);
digitalWrite(7, LOW);

delay(delay1);

digitalWrite(7, HIGH);
digitalWrite(8, LOW);

delay(delay1);

digitalWrite(8, HIGH);
}

and i did notice that when i slowed down the speed to one second intervals, only one button lit up. This might proove one of 2 things:

  1. I’m lacking of arduino coding knowledge, and just screwed up my code somehow…
    or 2. arduino is incapable of handling these kinds of speeds and changes so quickly, so the light from one button also gets sent to others…

oh yes, and i refer to analogwrite(3, 255) and then to analogwrite(3, 0) becuase 255 turns it on, and then i have to turn it off before it goes to the next button.

anybody?

I don't exactly understand what you're trying to do, by a 1ms delay will only have invisible effects... If you're expecting to see changes, set the delay to 1000 then eventually finetune it.

Maybe pictures or schematics of your setup could help...

this is just programing for an rgb button pad sold by spark fun. Originally started from the project a.squar made.

i'm using arduino dual core, but don't worry about that.

lets just say for now i'm using one regular arduino to power half of the button pad since it has 6 pwm ports, and the button pad has 6 connections that power half the board. So all i'm trying to achieve is powering the board, and running the lights every .01 seconds so i can change the colors, since if the grounds all connected at the same time, the whole row would light up the color i turned on.