-1

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.

1
  • As the error message says, you simply cannot have two functions with the same name. You need to move both sets of code into a single 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. Commented Jan 26, 2024 at 21:42

1 Answer 1

0

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.

Sign up to request clarification or add additional context in comments.

1 Comment

the idea is to have both LEDs flashing at the same time, as i will be using a camera based validator to verify that it displays the right number

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.