So I am just beginning to use arduino. I am trying to make a code but in the if statement, the outputs continue to be HIGH.
Here's my question:
Can someone find the error and also make the digitalWrite for pin 2 to 7 in fewer lines.
Please compile a new code.
int timer = 100;
const int ledPins[] = {
2, 7, 4, 6, 5, 3 };
int pinCount = 6;
const int analogPin = 0;
const int threshold = 500;
const int ledPin = 2;
const int ledPin1 = 3;
const int ledPin2 = 4;
const int ledPin3 = 5;
const int ledPin4 = 6;
const int ledPin5 = 7;
void setup() {
int thisPin;
for (int thisPin = 0; thisPin < pinCount; thisPin++) {
pinMode(ledPins[thisPin], OUTPUT);
pinMode(ledPin, OUTPUT);
}
}
void loop() {
int analogValue = analogRead(analogPin);
if (analogValue > threshold) {
for (int thisPin = 0; thisPin < pinCount; thisPin++) {
digitalWrite(ledPin,LOW);
digitalWrite(ledPin1,LOW);
digitalWrite(ledPin2,LOW);
digitalWrite(ledPin3,LOW);
digitalWrite(ledPin4,LOW);
digitalWrite(ledPin5,LOW);
while (digitalRead(ledPin) == HIGH) {
}
}
}
else {
for (int thisPin = 0; thisPin < pinCount; thisPin++) {
digitalWrite(ledPins[thisPin], HIGH);
delay(timer);
digitalWrite(ledPins[thisPin], LOW);
}
}
// loop from the highest pin to the lowest:
for (int thisPin = pinCount - 1; thisPin >= 0; thisPin--) {
// turn the pin on:
digitalWrite(ledPins[thisPin], HIGH);
delay(timer);
// turn the pin off:
digitalWrite(ledPins[thisPin], LOW);
delay(10000);
digitalWrite(ledPin,HIGH);
digitalWrite(ledPin1,HIGH);
digitalWrite(ledPin2,HIGH);
digitalWrite(ledPin3,HIGH);
digitalWrite(ledPin4,HIGH);
digitalWrite(ledPin5,HIGH);
delay(100);
}
}
Thanks