Hello, I am having some trouble with some code for a project I am working on. I am going to connect an LED RGD analog strip w/3 potentiometers controlling the brightness of each R G B color. In addition to controlling the brighting, I want to also put in a push button that will have several presets. I am having problems integrating the code of the push button with the potentiometer controlled LED light.
Button pushed (1)Red. Pushed again (2) Green (3)Blue (4)Purple (5) Yellow (6) White. (7) off
The code is below - and I keep getting errors.
Please help me finish this.
THANK YOU
.
const int redPin = 9;
const int greenPin = 10;
const int bluePin = 11;
const int redPotPin = 0;
const int greenPotPin = 1;
const int bluePotPin = 2;
int currentColorValueRed;
int currentColorValueGreen;
int currentColorValueBlue;
int buttonState = 0;
int buttonPin = 8;// must be declared
int counter = 0;
void setup()
{
pinMode ( buttonPin, INPUT); // switch pin input
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
}
void loop()
{
// Read the voltage on each analog pin then scale down to 0-255 and inverting the value for common anode
currentColorValueRed = (255 - map( analogRead(redPotPin), 0, 1024, 0, 255 ) );
currentColorValueBlue = (255 - map( analogRead(bluePotPin), 0, 1024, 0, 255 ) );
currentColorValueGreen = (255 - map( analogRead(greenPotPin), 0, 1024, 0, 255 ) );
}
{
if (buttonState == 1);
counter = counter+1;
if (counter == 4)
counter = 0;
}
do while (buttonState == 1){
buttonState = digitalRead (buttonPin);
analogWrite(redPin, currentColorValueRed);
analogWrite(bluePin, currentColorValueBlue);
analogWrite(greenPin, currentColorValueGreen);
do while (buttonState == 1);
buttonState == analogRead (buttonPin);
if (counter == 1) {
analogWrite REDPIN, HIGH);
digitalWrite GREENPIN, LOW);
digitalWrite BLUEPIN = LOW);
if (counter == 1) {
digitalWrite REDPIN, LOW);
digitalWrite GREENPIN, HIGH);
digitalWrite BLUEPIN = LOW);
if (counter == 1) {
digitalWrite REDPIN, LOW);
digitalWrite GREENPIN, LOW);
analogWrite BLUEPIN, HIGH);
if (counter == 1) {
analogWrite REDPIN, HIGH);
digitalWrite GREENPIN, LOW);
analogWrite BLUEPIN = HIGH); // purple
if (counter == 1) {
analogWrite REDPIN, HIGH);
analogWrite GREENPIN, HIGH);
digitalWrite BLUEPIN = LOW); // yellow
if counter == 1) {
analogWrite REDPIN, HIGH);
analogWrite GREENPIN, HIGH);
analogWrite BLUEPIN = HIGH); // white
if (counter == 0 )
digitalWrite REDPIN, LOW);
digitalWrite GREENPIN, LOW);
digitalWrite BLUEPIN = LOW);
}