I am currently working on a color theory project where you push a button to make three LEDS fade through colors that go along with the button pushed (cool color button makes leds fade though blue, purple, green).
Right now I have all three Superflux (shared anode) RGB LEDs hooked up. I plan on having 6 buttons with 6 different color words but right now I just have one and am trying to do some cool colors. My colors I want are red, orange and yellow but the LEDs don't light up at all. When I try blue, indigo, violet, they light up as pinks and red.
The only thing that I can see that could be wrong is maybe that I am using 150-Ohm resistors for every RGB pin of every LED and maybe that is wrong. Other than that I am sure I have everything hooked up right. Oh, well I think I do, When I unplug the wire hooked from the 5V to the + row on the breadboard (which then has a wire going to the anode on each LED) it doesn't change anything and the LEDs are still lit up. Can they get power from the PWM inputs?
Here is the sketch...
struct color
{
unsigned char red;
unsigned char green;
unsigned char blue;
};unsigned char buttonPin = 3;
color ledPins = { 9, 10, 11 };color black = { 0, 0, 0 };
color white = { 255, 255, 255 };color red = { 255, 0, 0 };
color orange = { 255, 127, 0 };
color yellow = { 255, 255, 0 };void setup()
{
pinMode(buttonPin, INPUT);
pinMode(ledPins.red, OUTPUT);
pinMode(ledPins.green, OUTPUT);
pinMode(ledPins.blue, OUTPUT);
}void showColor(struct color pins, struct color values)
{
analogWrite(pins.red, values.red);
analogWrite(pins.green, values.green);
analogWrite(pins.blue, values.blue);
}void fadeToColor(struct color pins, struct color oldValues, struct color newValues, int delayMillisec)
{
float rdiff = (float)((int)newValues.red - oldValues.red) / delayMillisec;
float gdiff = (float)((int)newValues.green - oldValues.green) / delayMillisec;
float bdiff = (float)((int)newValues.blue - oldValues.blue) / delayMillisec;float r = oldValues.red;
float g = oldValues.green;
float b = oldValues.blue;
for (int i = 0; i < delayMillisec; i++)
{
r += rdiff;
g += gdiff;
b += bdiff;analogWrite(pins.red, r);
analogWrite(pins.green, g);
analogWrite(pins.blue, b);delayMicroseconds(1000);
if (!isRunning())
return;
}
}bool isRunning()
{
static bool pushed = false;
static bool running = true;
if (digitalRead(buttonPin) == LOW)
{
if (!pushed)
{
running = !running;
pushed = true;
}
}
else
{
pushed = false;
}
return running;
}int pos = 0;
color colors[] = { black, red, orange, yellow };
int numColors = sizeof(colors) / sizeof(color);void loop()
{
if (isRunning())
{
int last = pos;
pos++;
if (pos >= numColors)
pos = 0;fadeToColor(ledPins, colors[last], colors[pos], 700);
if (isRunning())
delay(300);
}
else
{
showColor(ledPins, black);
}
}
If I knew how to draw a diagram better I would and if it is necessary to fully access my problem I will try.
Thanks so much for any help you can give me.
- Aidyn