Sorry for the newbish question here, but I am new to C programming, as well as the arduino.
So, I am working on trying to get the Night Rider effect with 8 LEDs (dig outs 2-9). I want to control the speed with a POT. Now, I was able to do so, with calling each LED in sequence (2,3,4,5,6,7,8,9,8,7,6,5,4,3 loop). SO, I started trying to clean up the code a bit with a couple nested if statements.
int sensorPin = A0;
int ledPin = 2;
int sensorValue = 0;
int reverse = 0;
void setup() {
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
}
void loop() {
if (reverse = 0); { // count up
digitalWrite(ledPin, HIGH);
sensorValue = analogRead(sensorPin);
delay(sensorValue);
digitalWrite(ledPin, LOW);
sensorValue = analogRead(sensorPin);
delay(sensorValue);
if (ledPin = 9) {
reverse = 1; }
else ledPin = (ledPin + 1);
}
[u][b] else // count down[/b][/u]
digitalWrite(ledPin, HIGH);
sensorValue = analogRead(sensorPin);
delay(sensorValue);
digitalWrite(ledPin, LOW);
sensorValue = analogRead(sensorPin);
delay(sensorValue);
if (ledPin = 2) {
reverse = 0; }
else ledPin = (ledPin - 1);
However, I am getting
sketch_jun30b.cpp: In function 'void loop()':
sketch_jun30b:29: error: 'else' without a previous 'if'
with the bolded underlined portion of code being pointed out. Why isn't that "else" associated with the very 1st "if"?