I was trying to do a LED display that turns on a LED at pin 13 that goes on then turns off after a delay then the next pin (which is pin 12 counting down) will turn on and then turn off.
I also put in a potentiometer that can change the delay to make it faster or slower.
Here's the code:
float pinOn = 13;
int outMin = 0;
int outMax = 13;
float delayNum = 1000;
void setup () {
for (int i=outMin; i<=outMax; i++) {
pinMode(i, OUTPUT); }
Serial.begin(9600);
}
void loop () {
// Reads Potentiometer -- sets delay relative to the Potentiometer input
int sensorValue = analogRead(A0);
delayNum = sensorValue;
// Turns on the Pin designated by 'pinOn'
digitalWrite(pinOn, HIGH);
delay(delayNum);
digitalWrite(pinOn, LOW);
// Checks if 'pinOn' is 0 which then resets it back to 13 if not 0 then counts down
if (pinOn = 0) {
pinOn + 13;
} else {
pinOn - 1;
}
}
All it does is turn on pin 13 for a moment then permanently turns on pin 1 and 0 and it gets stuck like that.
if (a = b)
and warn you about it if you enable all warnings and, ideally, make it treat warnings as errors. I also think this counts as a "general coding" problem; if you replaced the contents of the blocks withputs("foo")
or other non-Arduino C statements, the answer would be exactly the same.