Hello,
I am new to coding for Arduino and EE projects but have some experience in python so I understand most of what is going on. I am trying to create a code that will run individual loops for my breadboard. I have four LDR/LED circuits and my goal is to the LED light up if receiving a certain amount of light. I believe the best way about this is to run an individual loop so that is what direction I went with it. I think my I am receiving a redefinition of 'void loop' error but it is only being thrown on my third loop?
Any advice in general or response to my theory of code would be helpful.
//Light Tracker Coding
int firstLEDpin = 2; // 1stpin from VS LED is connected to
int secondLEDpin = 3; // 2nd pin from VS LED is connected to
int thirdLEDpin = 4; // 3rd pin from VS is connected to
int fourthLEDpin = 5; // 4th pin from VS is connected to
int lightSensorPin1 = A0; // PIN1 Light Sensor is connected to
int lightSensorPin2 = A1; // PIN1 Light Sensor is connected to
int lightSensorPin3 = A2; // PIN1 Light Sensor is connected to
int lightSensorPin4 = A3; // PIN1 Light Sensor is connected to
int analogValue = 0;
void setup() {
//Set pins to outputs
pinMode(firstLEDpin, OUTPUT);
pinMode(secondLEDpin,OUTPUT);
pinMode(thirdLEDpin,OUTPUT);
pinMode(fourthLEDpin,OUTPUT);
}
void loop(){
analogValue = analogRead(lightSensorPin1); //If 1st pin has the greatest light
if(analogValue < 25){
digitalWrite(firstLEDpin, HIGH);
}
else if(analogValue >= 25 && analogValue <= 50){ //If 1nds pin has the greatest light
digitalWrite(secondLEDpin, HIGH);
}
else if(analogValue >= 50 && analogValue <= 100){ //If 3rd pin has the greatest light
digitalWrite(thirdLEDpin, HIGH);
}
else{
digitalWrite(fourthLEDpin, HIGH); //If 4th pin has the greatest light
}
delay(200);
digitalWrite(firstLEDpin, LOW); //LED OFF
digitalWrite(secondLEDpin, LOW); //LED OFF
digitalWrite(thirdLEDpin, LOW); //LED OFF
digitalWrite(fourthLEDpin, LOW); //LED OFF
}
void loop(){
analogValue = analogRead(lightSensorPin2);
if(analogValue < 25){
digitalWrite(secondLEDpin, HIGH); //If 2nd pin has the greatest light
}
else if(analogValue >= 25 && analogValue <= 50){ //If 3rd pin has the greatest light
digitalWrite(thirdLEDpin, HIGH);
}
else if(analogValue >= 50 && analogValue <= 100){ //If 4th pin has the greatest light
digitalWrite(fourthLEDpin, HIGH);
}
else{
digitalWrite(firstLEDpin, HIGH); //If 1st pin has the greatest light
}
delay(200);
digitalWrite(firstLEDpin, LOW); //LED OFF
digitalWrite(secondLEDpin, LOW); //LED OFF
digitalWrite(thirdLEDpin, LOW); //LED OFF
digitalWrite(fourthLEDpin, LOW); //LED OFF
}
void loop(){
analogValue = analogRead(lightSensorPin3); //If 3rd pin has the greatest light
if(analogValue < 25){
digitalWrite(thirdLEDpin, HIGH);
}
else if(analogValue >= 25 && analogValue <= 50){ //If 4th pin has the greatest light
digitalWrite(fourthLEDpin, HIGH);
}
else if(analogValue >= 50 && analogValue <= 100){ //If 1st pin has the greatest light
digitalWrite(firstLEDpin, HIGH);
}
else{
digitalWrite(secondLEDpin, HIGH); //If 2nd pin has the greatest light
}
delay(200);
digitalWrite(firstLEDpin, LOW); //LED OFF
digitalWrite(secondLEDpin, LOW); //LED OFF
digitalWrite(thirdLEDpin, LOW); //LED OFF
digitalWrite(fourthLEDpin, LOW); //LED OFF
}
void loop(){
analogValue = analogRead(lightSensorPin4);
if(analogValue < 25){
digitalWrite(fourthLEDpin, HIGH); //If 4th pin has the greatest light
}
else if(analogValue >= 25 && analogValue <= 50){ //if 3rd pin has the greatest light
digitalWrite(thirdLEDpin, HIGH);
}
else if(analogValue >= 50 && analogValue <= 100){ //if 2nd pin has the greatest light
digitalWrite(secondLEDpin, HIGH);
}
else{
digitalWrite(firstLEDpin, HIGH); //if 1st pin has the great light
}
delay(200);
digitalWrite(firstLEDpin, LOW); //LED OFF
digitalWrite(secondLEDpin, LOW); //LED OFF
digitalWrite(thirdLEDpin, LOW); //LED OFF
digitalWrite(fourthLEDpin, LOW); //LED OFF