0

My teacher gave us a performance output about doing a dancing christmas lights in tinkercad. But I don't know what to do about the codes. He left an instruction to us about what to do. I follow it but the tinkercad keep telling that...

Sorry, it seems like your code has some errors.
Close
 In function 'void setup()':
13:5: error: a function-definition is not allowed here before '{' token
21:7: error: a function-definition is not allowed here before '{' token
41:61: error: expected '}' at end of input
41:61: error: expected '}' at end of input
41:61: error: expected '}' at end of input
 exit status 1

And here's the code that I've entered...

int ledPins[]={3,4,5,6,7,8,9,10,11,12};
void setup()
{
  for(int i =0; i <11; i++)
  {
    pinMode(ledPins[i],OUTPUT);
}
  {
  void setup()
    {
     for (int i=0; i <11; i++)
     {
       pinMode(ledPins[i],OUTPUT);
     }
  }
    {
      void loop()
      {
        int i = 0;
        while (i<10)
          
        {
          {
            digitalWrite(ledPins{i],HIGH);
            delay(100);
            digitalWrite(ledPins[i],LOW);
            i++;
                                }
                         }
                         i = 10;
                         while (i >0
                                {
                                  digitalWrite(ledPins[i],HIGH;
                                               delay(100);
                                               digitalWrite(ledPins[i],LOW;
                                                            i--;
                                                            }
                                                            }

And here's the instruction of my teaher for the codes...

6. Initialize variables Use array to initialize variables. Set ledPin as the name of the variable and initialize the Arduino pins that you’re going to use. Never forget to end each statement with semicolon

7. Set all pin to output Use function void setup () Create a for () loop for array manipulation. Initialize the for loop with i=0; since we will start the dancing lights with all LEDs turned off. Initialize the condition i<11; since we need to turn on the 10 LEDs.

Set the increment to i++ because we need to iterate until it reaches the last LED. Configure pin using pinMode(). Place a curly bracket before and after the for loop and pinMode(). 8. Create a loop Use function void loop(). Create a variable, i = 0. Use while() for continuous looping First while() is used to run your light from right to left. 

Second while() is used to run your light from left to right.  Place a curly bracket before and after your statement block Never forget to end each statement with semicolon

  • 2
    You seem to have brackets-tourettes. You really need to look at those brackets. Examine the shape of them, and the order of them. Hint: for every opening { there must be a closing }. For every opening ( there must be a closing ). For every opening [ there must be a closing ]. – Majenko Sep 11 at 14:15
  • 1
    Are those the only codes that I need to change? – Janelle Sep 11 at 14:19
  • 1
    I don't know. Your code is such a mess I have no clue what it's intending to do. – Majenko Sep 11 at 14:19
  • 1
    you really need to look at the example code in the Arduino IDE ... see how the code is formatted, which means how it is indented ... indent levels are like paragraphs in writing ... your code has indentation, but it is all over the place without reason – jsotola Sep 11 at 14:33
  • 1
    Does this answer your question? What's wrong with my codes? – sempaiscuba Sep 11 at 15:05
1

I changed it, so it at least compiles.

int ledPins[]={3,4,5,6,7,8,9,10,11,12};
void setup()
{
  for(int i=0; i < 11; i++)
  {
    pinMode(ledPins[i],OUTPUT);
  }
}

void loop()
{
  int i = 0;
  while (i < 10)
  {
    digitalWrite(ledPins[i],HIGH);
    delay(100);
    digitalWrite(ledPins[i],LOW);
    i++;
  }
  i = 10;
  while (i > 0)
  {
    digitalWrite(ledPins[i],HIGH);
    delay(100);
    digitalWrite(ledPins[i],LOW);
    i--;
  }
}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.