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