Hi all,
I have been Arduino-ing for all of 3 days now and I decided to try my first solo project. Unfortunately it hasn't worked, and despite reading through all the examples I can't seem to figure it out for myself.
I have a potentiometer wired in for an analog listen, and 3 outs to light LEDs. I'm trying to get the potentiometer to sequentially light up each LED as I turn it.
Literally nothing happens when I run the code and fiddle with the pot. Not a single LED lights up.
int LED1 = 13;
int LED2 = 12;
int LED3 = 11;
int potPin = A0;
int val;
void setup() {
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(LED3, OUTPUT);
}
void loop() {
val = analogRead(potPin);
val = map(val, 0, 1023, 0, 180);
if (val = 0) {
digitalWrite(LED1, LOW);
digitalWrite(LED2, LOW);
digitalWrite(LED3, HIGH);
} else if (val > 200) {
digitalWrite(LED1, HIGH);
digitalWrite(LED2, LOW);
digitalWrite(LED3, LOW);
} else if (val > 400) {
digitalWrite(LED1, HIGH);
digitalWrite(LED2, HIGH);
digitalWrite(LED3, LOW);
} else {
digitalWrite(LED1, HIGH);
digitalWrite(LED2, HIGH);
digitalWrite(LED3, HIGH);
}
delay(1);
}
One note: I'm pretty sure I don't need the line "val = map(val, 0, 1023, 0, 180);" but I threw it in just in whilst trying to troubleshoot, as I had used similar code in a simple potentiometer/servo project.
My wiring: +5v and ground to power rail's + & -, pot + & - to power rail and listen to A0, 13 out to 220 ohm resistor to LED then to ground rail.
Each part of the circuit works with my power supply, so I'm certain it's the code that's the problem.
Thanks for reading, and for any help you can lend.