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.
void loop() { ... }structure - I can't tell you what form that would take, since I have no idea how your two current sets of code are supposed to interact.