I was tasked with a college project which involved programming an Arduino board to flash two LEDs , which would display a number in binary code. I am about halfway through, but when I attempt to upload the program it keeps flashing the following error message. I have attached the code I have written so far and the error message below.
void setup()
{
// Set pin D2 as a digital output to control the LED
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
}
// The loop routine runs over and over until the power is switch off.
void loop()
{
digitalWrite(2, HIGH); // Turn the LED on
delay(1000); // 1000 ms delay
digitalWrite(2, LOW); // Turn the LED off
delay(1000); // 1000 ms delay
}
void loop()
{
digitalWrite(3, LOW);
delay(10000);
digitalWrite(3, HIGH);
delay(5000);
digitalWrite(3, LOW);
delay(2000);
digitalWrite(3, HIGH);
delay(1000);
digitalWrite(3, LOW);
delay(1000);
digitalWrite(3, HIGH);
delay(1000);
digitalWrite(3, LOW);
delay(8000);
digitalWrite(3, HIGH);
delay(8000);
digitalWrite(3, LOW);
delay(4000);
digitalWrite(3, HIGH);
delay(1000);
digitalWrite(3, LOW);
delay(5000);
Error:
C:\Users\matth\OneDrive\Documents\Arduino\flash\flash.ino: In function 'void loop()':
C:\Users\matth\OneDrive\Documents\Arduino\flash\flash.ino:21:6: error: redefinition of 'void loop()'
void loop()
^~~~
C:\Users\matth\OneDrive\Documents\Arduino\flash\flash.ino:14:6: note: 'void loop()' previously defined here
void loop()
^~~~
exit status 1
Compilation error: redefinition of 'void loop()
I tried removing the second void loop command, and also moving the digital input designation from between the two loops to above the first. However, I have no experience whatsoever with programming so I don't really know how to troubleshoot.
You have 2 loop functions - you can only have one. Remove one and it should compile and load fine.
Then it is just a matter of doing whatever you want it to do in the loop codewise.
Currently look like one loop is to turn on/off pin 2.
The other loop setting pin 3 high and low with various delays between the on/off
more information on how you are expecting the value to be flown on the pins would be needed.