Hey i'm new to Ardruino and ive been trying to cobble together a code from existing examples
I have 4 output LED and i want them to fade (simple! figured this out :D)
I then want to push a button and for the fade sequence to stop and only one LED (White AKA pin 11) to display constant. (Difficult! Cant solve 0_0)
Here is the code i have figured out so far, can anyone help with the button
//RGB LED - fading between colors
//pin connections
int red = 6;
int green = 9;
int blue = 10;
int white = 11;
int buttonPin = 2;
boolean currentState = LOW;//stroage for current button state
boolean lastState = LOW;//storage for last button state
void setup(){
pinMode(buttonPin, INPUT);
pinMode(red, OUTPUT);
pinMode(blue, OUTPUT);
pinMode(green, OUTPUT);
pinMode(white, OUTPUT);
}
if (currentState == HIGH && lastState == LOW)
Serial.println("pressed");
delay(1);
fader(red,green);
fader(green,blue);
fader(blue, white);
fader(white,red);
fader(white,white);
}
void fader(int color1, int color2){
for (int brightness=0;brightness<256;brightness++){
analogWrite(color1, 255-brightness);
analogWrite(color2, brightness);
delay(10);
}
}
Hi, please post the sketch you have successfully running on the Arduino and we can move forward from there.
The sketch you just posted will not even verify! It is missing the "loop()" function, your "if" statement is not within any function at all, and you have an unmatched "}".
this may not be exactly what you want, but it actually does something.
looks like you were missing a few lines that you cut out, perhaps.
maybe you can figure out how to get that button press working, using those blocking fades.
//RGB LED - fading between colors
//pin connections
int red = 6;
int green = 9;
int blue = 10;
int white = 11;
int buttonPin = 2;
boolean currentState = LOW;//stroage for current button state
boolean lastState = HIGH;//storage for last button state
void setup()
{
pinMode(buttonPin, INPUT);
pinMode(red, OUTPUT);
pinMode(blue, OUTPUT);
pinMode(green, OUTPUT);
pinMode(white, OUTPUT);
}
void loop()
{
if (currentState == HIGH && lastState == LOW)
{
Serial.println("pressed");
}
delay(25);
fader(red, green);
fader(green,blue);
fader(blue, white);
fader(white,red);
fader(white,white);
}
void fader(int color1, int color2)
{
for (int brightness=0;brightness<256;brightness++)
{
analogWrite(color1, 255-brightness);
analogWrite(color2, brightness);
delay(10);
}
}