Need help with homework (Paul McWhorter lesson 3)

Hi everyone,

I am completely new to electronics and have just bought an Arduino and I am going through the tutorial lessons of Paul McWhorter. I am currently on lesson 3.

I am trying to make my red LED blink 5 times with a 500 milisecond delay and stop, the green LED blink 10 times with a 500 milisecond delay and stop and the blue LED blink 15 times with a with a 500 milisecond delay and stop, but I get an error message.

Could you please help?

[Post Edit]
I have seen many posts on this forum of similar requests, but they all used buttons and code I don't yet understand, which is why I have posted this. I'm trying to do this without a button.
[Post Edit End]

My code is here:


void setup() {
// put your setup code here, to run once:

// [Paul McWhorter YouTube Lesson 3 homework]

// I am putting all of my code in the voide setup instead of using the void loop section, so my code will only run once and stop.

pinMode (2, OUTPUT);
}

{
pinMode (4, OUTPUT);
}

{
pinMode (6, OUTPUT);
}

{

// Making my red LED  blink 5 times with a 500 milisecond delay, then stop
  digitalWrite (2, HIGH);
delay (500);
digitalWrite (2, LOW);
delay (500);

digitalWrite (2, HIGH);
delay (500);
digitalWrite (2, LOW);
delay (500);

digitalWrite (2, HIGH);
delay (500);
digitalWrite (2, LOW);
delay (500);

digitalWrite (2, HIGH);
delay (500);
digitalWrite (2, LOW);
delay (500);

digitalWrite (2, HIGH);
delay (500);
digitalWrite (2, LOW);
delay (500);
}

{
// Making my green LED  blink 10 times with a 500 milisecond delay, then stop
  digitalWrite (4, HIGH);
delay (500);
digitalWrite (4, LOW);
delay (500);

digitalWrite (4, HIGH);
delay (500);
digitalWrite (4, LOW);
delay (500);

digitalWrite (4, HIGH);
delay (500);
digitalWrite (4, LOW);
delay (500);

digitalWrite (4, HIGH);
delay (500);
digitalWrite (4, LOW);
delay (500);

digitalWrite (4, HIGH);
delay (500);
digitalWrite (4, LOW);
delay (500);

digitalWrite (4, HIGH);
delay (500);
digitalWrite (4, LOW);
delay (500);

digitalWrite (4, HIGH);
delay (500);
digitalWrite (4, LOW);
delay (500);

digitalWrite (4, HIGH);
delay (500);
digitalWrite (4, LOW);
delay (500);

digitalWrite (4, HIGH);
delay (500);
digitalWrite (4, LOW);
delay (500);

digitalWrite (4, HIGH);
delay (500);
digitalWrite (4, LOW);
delay (500);
}

{
// Making my blue LED  blink 15 times with a 500 milisecond delay, then stop
  digitalWrite (6, HIGH);
delay (500);
digitalWrite (6, LOW);
delay (500);

digitalWrite (6, HIGH);
delay (500);
digitalWrite (6, LOW);
delay (500);

digitalWrite (6, HIGH);
delay (500);
digitalWrite (6, LOW);
delay (500);

digitalWrite (6, HIGH);
delay (500);
digitalWrite (6, LOW);
delay (500);

digitalWrite (6, HIGH);
delay (500);
digitalWrite (6, LOW);
delay (500);

digitalWrite (6, HIGH);
delay (500);
digitalWrite (6, LOW);
delay (500);

digitalWrite (6, HIGH);
delay (500);
digitalWrite (6, LOW);
delay (500);

digitalWrite (6, HIGH);
delay (500);
digitalWrite (6, LOW);
delay (500);

digitalWrite (6, HIGH);
delay (500);
digitalWrite (6, LOW);
delay (500);

digitalWrite (6, HIGH);
delay (500);
digitalWrite (6, LOW);
delay (500);

digitalWrite (6, HIGH);
delay (500);
digitalWrite (6, LOW);
delay (500);

digitalWrite (6, HIGH);
delay (500);
digitalWrite (6, LOW);
delay (500);

digitalWrite (6, HIGH);
delay (500);
digitalWrite (6, LOW);
delay (500);

digitalWrite (6, HIGH);
delay (500);
digitalWrite (6, LOW);
delay (500);

digitalWrite (6, HIGH);
delay (500);
digitalWrite (6, LOW);
delay (500);
}

void loop() {
// put your main code here, to run repeatedly:
// left empty because I don't want my program to loop

}

My error is here:


Arduino: 1.8.13 (Windows 10), Board: "Arduino Uno"

Blinking_lights_a_set_amount_of_times_project:11:1: error: expected unqualified-id before '{' token

{

^

Blinking_lights_a_set_amount_of_times_project:15:1: error: expected unqualified-id before '{' token

{

^

Blinking_lights_a_set_amount_of_times_project:19:1: error: expected unqualified-id before '{' token

{

^

Blinking_lights_a_set_amount_of_times_project:48:1: error: expected unqualified-id before '{' token

{

^

Blinking_lights_a_set_amount_of_times_project:101:1: error: expected unqualified-id before '{' token

{

^

exit status 1

expected unqualified-id before '{' token

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.


I am aware of variables and integers, because I have seen lesson 4, (I haven't seen a past level 4) but it must be possible to do this without, otherwise Paul wouldn't have told me to.

Any help is most appreciated.

Thanks,
Adam

void setup (void)
{
  // Put your code here
}

void loop(void)
{}

I am going through the tutorial lessons of Paul McWhorter. I am currently on lesson 3.

A link would be useful, for those who have no idea who Paul McWhorter is.

Sorry,

I wasn't aware I could post links.

The video I am referring to is here:

void setup() {
 // put your setup code here, to run once:

 // [Paul McWhorter YouTube Lesson 3 homework]

 // I am putting all of my code in the voide setup instead of using the void loop section, so my code will only run once and stop.
 
pinMode (2, OUTPUT);
} // <<< Your setup end here

Hi Adam,
Please go back and edit your first post so as t use code tags </> around your code. Please read How to use this forum
Especially item #7 on posting code if you don’t know how to do this. Doing so makes it easier to read.

[EDIT] I was going to post again with a hint as to what is wrong with your code, but AWOL beat me to it.

That's better, thank you.

Has AWOL's hint been enough to at least get you thinking about what the problem is?

Thanks for the hint AWAL!

Thank you both for your help! :slight_smile:

I deleted all my curly brackets apart from one at the start and one at the end and it works now!:

void setup()
  // put your setup code here, to run once:

  // [Paul McWhorter YouTube Lesson 3 homework]

  // I am putting all of my code in the voide setup instead of using the void loop section, so my code will only run once and stop.

  {
  pinMode (2, OUTPUT);

  pinMode (4, OUTPUT);

  pinMode (6, OUTPUT);


// Making my red LED  blink 5 times with a 500 milisecond delay, then stop
    digitalWrite (2, HIGH);
  delay (500);
  digitalWrite (2, LOW);
  delay (500);

  digitalWrite (2, HIGH);
  delay (500);
  digitalWrite (2, LOW);
  delay (500);

  digitalWrite (2, HIGH);
  delay (500);
  digitalWrite (2, LOW);
  delay (500);

  digitalWrite (2, HIGH);
  delay (500);
  digitalWrite (2, LOW);
  delay (500);

  digitalWrite (2, HIGH);
  delay (500);
  digitalWrite (2, LOW);
  delay (500);

// Making my green LED  blink 10 times with a 500 milisecond delay, then stop
    digitalWrite (4, HIGH);
  delay (500);
  digitalWrite (4, LOW);
  delay (500);

  digitalWrite (4, HIGH);
  delay (500);
  digitalWrite (4, LOW);
  delay (500);

  digitalWrite (4, HIGH);
  delay (500);
  digitalWrite (4, LOW);
  delay (500);

  digitalWrite (4, HIGH);
  delay (500);
  digitalWrite (4, LOW);
  delay (500);

  digitalWrite (4, HIGH);
  delay (500);
  digitalWrite (4, LOW);
  delay (500);

  digitalWrite (4, HIGH);
  delay (500);
  digitalWrite (4, LOW);
  delay (500);

  digitalWrite (4, HIGH);
  delay (500);
  digitalWrite (4, LOW);
  delay (500);

  digitalWrite (4, HIGH);
  delay (500);
  digitalWrite (4, LOW);
  delay (500);

  digitalWrite (4, HIGH);
  delay (500);
  digitalWrite (4, LOW);
  delay (500);

  digitalWrite (4, HIGH);
  delay (500);
  digitalWrite (4, LOW);
  delay (500);


// Making my blue LED  blink 15 times with a 500 milisecond delay, then stop
    digitalWrite (6, HIGH);
  delay (500);
  digitalWrite (6, LOW);
  delay (500);

  digitalWrite (6, HIGH);
  delay (500);
  digitalWrite (6, LOW);
  delay (500);

  digitalWrite (6, HIGH);
  delay (500);
  digitalWrite (6, LOW);
  delay (500);

  digitalWrite (6, HIGH);
  delay (500);
  digitalWrite (6, LOW);
  delay (500);

  digitalWrite (6, HIGH);
  delay (500);
  digitalWrite (6, LOW);
  delay (500);

  digitalWrite (6, HIGH);
  delay (500);
  digitalWrite (6, LOW);
  delay (500);

  digitalWrite (6, HIGH);
  delay (500);
  digitalWrite (6, LOW);
  delay (500);

  digitalWrite (6, HIGH);
  delay (500);
  digitalWrite (6, LOW);
  delay (500);

  digitalWrite (6, HIGH);
  delay (500);
  digitalWrite (6, LOW);
  delay (500);

  digitalWrite (6, HIGH);
  delay (500);
  digitalWrite (6, LOW);
  delay (500);

  digitalWrite (6, HIGH);
  delay (500);
  digitalWrite (6, LOW);
  delay (500);

  digitalWrite (6, HIGH);
  delay (500);
  digitalWrite (6, LOW);
  delay (500);

  digitalWrite (6, HIGH);
  delay (500);
  digitalWrite (6, LOW);
  delay (500);

  digitalWrite (6, HIGH);
  delay (500);
  digitalWrite (6, LOW);
  delay (500);

  digitalWrite (6, HIGH);
  delay (500);
  digitalWrite (6, LOW);
  delay (500);
}

void loop() {
  // put your main code here, to run repeatedly:
  // left empty because I don't want my program to loop

}

Well done!

Do you understand why?

Thanks! :slight_smile:

I believe so.

I was putting my code in the part of the set up that is only going to run once, so it would get to here:

void setup() {
// put your setup code here, to run once:

// [Paul McWhorter YouTube Lesson 3 homework]

// I am putting all of my code in the voide setup instead of using the void loop section, so my code will only run once and stop.

pinMode (2, OUTPUT);
}

and stop, then I gues it wouldn't know what to do with the rest of the code?

Sort of.
Your next homework is to find out exactly what a pair of {} means.

Thanks Perry!

I'll work on that and reply back once I have the answer.

I really like that you're giving me hints and giving me things to work on.
Other forums I've been on about other subjects, they just give me the answer in a way I don't understand and I don't really learn anything.

mazdamj:
I'll work on that and reply back once I have the answer.

++Karma; // I like that that's what you want.
We see too many questions on here that could be written as 'I don't have a clue, never will have so just tell me the answer'. Those people don't last long :o

Wow, lesson 3 and 26 minutes in and we’ve only just got to flashing a LED?!
Really milking the youtube views me thinks.

pcbbc:
Wow, lesson 3 and 26 minutes in and we’ve only just got to flashing a LED?!
Really milking the youtube views me thinks.

I didn't see the video, but don't forget, if you are starting completely from scratch there is at least the IDE installation and set up to program a board. If you know absolutely nothing, there are a few things you have to get going in the beginning.

PerryBebbington:
++Karma; // I like that that's what you want.
We see too many questions on here that could be written as 'I don't have a clue, never will have so just tell me the answer'. Those people don't last long :o

That's great thanks Perry! :slight_smile:

PerryBebbington:
Sort of.
Your next homework is to find out exactly what a pair of {} means.

I researched what {} means and the way I understand it now is, you need an open curly after the void setup() function to signify the start of that function.

Then you input all of your code that goes with that function, Then you don't need the closing curly until the end of that function.

Then when you do the void loop() function, you need another open curly to signify the start of that function, then you input all of your code for that function, then put a closed curly to signify the end of that function.

As far as I can tell, you don't need any curly brackts in any other parts of any program.

Am I right?

Thanks,
Adam

Am I right?

No, keep searching.

Consider that it is not just about setup and loop, they are used in other places too.

Not quite Adam. A typical program could have many different sections (functions). Each function is contained within the braces. A nicely structured program would have nothing in the loop except calls to the functions.

The beauty of functions is that you don't need to keep repeating pieces of code, you just call the function.

This reference page on curly braces will be of interest

{} - Arduino Reference(also%20referred%20to,by%20a%20closing%20curly%20brace%20%7D%20.