It says 'counter is not declared in this scope'

Basically, I'm trying to get the LED on an Arduino Uno Module to blink three times for like half a second, then move on to making it blink on loop every second.

This is what I have so far aaand im a total newbie and have no idea what's going on, any help would be great. Thank you :3

void setup() {
pinMode(13, OUTPUT);
}

void loop() 
{
  for (counter = 0; counter < 3; ++counter){
    digitalWrite(13, HIGH); 
    delay(500); //will light up for 500 milliseconds or half a second in each sequence
    digitalWrite(13, LOW);
   delay(500);
    digitalWrite(13, LOW);
  }
}

void loop() {
digitalWrite(13, HIGH); 
delay(1000); //will light up for 1000 milliseconds or one second in each sequence
digitalWrite(13, LOW);
delay(1000);
}

try

 for (int counter = 0; counter < 3; ++counter)

be aware that this increments the counter BEFORE using it... you probably want counter++ ?

Also - looks like you have 2 loop() s ... ?

Try putting your 3 blinks code into setup. After the blinks, the program will move to loop and do the 1 sec delays.

you also need to declare your counter variable before setup.

int counter;

-fab

thanks, that worked! Although now it says 'redefinition of void loop()' then highlighted the first-ish line with words from here

}

void loop() {
digitalWrite(13, HIGH); 
delay(1000); //will light up for 1000 milliseconds or one second in each sequence
digitalWrite(13, LOW);
delay(1000);
}

whoops yes, i was following a tutorial from youtube to get this homework finished but it doesnt seem to be working and im not sure what im doing wrong :')

Think about it a bit more…
A single ‘blink’ function… called from loop()

Use millis() timing when calling the ‘blink’ function,, and you can adjust the blink rate any time for any duration.

Lose the delay()s completely.

Once that’s working you can do many other things while the LEDs are blinking ‘in the background’.

thanks, it worked! :DD