Hey, I am trying to have three LEDS hooked up and be able to turn them on and off using a potentiometer. This is homework from Paul Mcwhorter Arduino series episode 13. This is the code I've made however only the redLed is turning on. Is there a mistake in the code or is just faulty LEDs on my part?
Thanks in advance!
int myPin=A2;
int readVal;
int delayT=250;
float V2;
int redPin=9;
int greenPin=8;
int bluePin=7;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(myPin, INPUT);
pinMode(redPin,OUTPUT);
pinMode(greenPin,OUTPUT);
pinMode(bluePin,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
readVal=analogRead(myPin);
V2=(5./1023.)*readVal;
Serial.print("Potentiometer Voltage is ");
Serial.println(V2);
if (V2<=3.0){
digitalWrite(greenPin,HIGH);
}
if (V2>=3.0){
digitalWrite(greenPin,LOW);
}
if (V2>3 && V2<4){
digitalWrite(bluePin,HIGH);
}
if (V2<3 || V2>4){
digitalWrite(bluePin,LOW);
}
if (V2>4.0){
digitalWrite(redPin,HIGH);
}
if (V2<4.0){
digitalWrite(redPin,LOW);
}
@reefy29 And also, please include a copy of your schematic. The old-timers will be asking for both your software code (auto formatted and within code tags!) plus the circuit diagram. It makes things a lot easier to understand what's going on!
Thank you!