Hello,
I am a new coder and I am trying to configure a program that allows me to change the brightness of one colour on the RGB LED using a potentiometer, but I can switch between the 3 colours using a push button.
The catch is that, when I push the button, the previous colour is still visible (and even mixes with the new new colour).
For example, it starts on red and I move the potentiometer to make it a light-red, when I push the button to change it to green, it is a mix between a light red and a green.
This is for a school project and I have no idea how to make this work.
Does anyone have any pointers or ways to make this work?
I will post my link below to tinkercad, but I will also paste my code here too!
I am a new coder, so I know it will probably be completely wrong and have a ton of mistakes, so take it easy! I'm trying to learn because I do not understand Arduino's or breadboards very well, along with the coding that is involved.
My code:
void level3(){
if (digitalRead(buttonPin1)==HIGH)){
data= analogRead(rotationPin);
data = map(data,0,1023,0,255);
Serial.println(data);
analogWrite(RGBGreenPin,data);
delay(5);
}
else{
digitalRead(buttonPin1)== LOW;
}
if (digitalRead(buttonPin1)==HIGH)){
data= analogRead(rotationPin);
data = map(data,0,1023,0,255);
Serial.println(data);
analogWrite(RGBRedPin,data);
delay(5);
}
else{
digitalRead(buttonPin1)== LOW;
if (digitalRead(buttonPin1)== HIGH)){
data= analogRead(rotationPin);
data = map(data,0,1023,0,255);
Serial.println(data);
analogWrite(RGBBluePin,data);
delay(5);
}
else{
digitalRead(buttonPin1)==LOW;
}
}
}