I need help w an error

Hi, I am new to programming and even newer to Arduino programming. I need help with an error that I get frequently. When I place a } closing the Void Loop code, I get the following error:

In function 'void loop()':
33:1: error: expected ';' before '}' token.
avr[0m 1.8.6 [90m/home/tcad/.arduino15/packages/arduino/hardware/avr/1.8.6[0m
exit status 1

What I'm trying to make are two semaphores, which work like everyday semaphores, but I get this error. In addition to when I am about to finish executing the code, and then continue looping, the green led of the first traffic light, turns on, but also the red led of the first traffic light and the green led of the second traffic light. I don't know if someone could help me (it is for an assignment and I need it before 10pm).

Please read:

and post your code as described. How are we to know what you've done wrong, if you don't show us what you've done?

Sounds like you didn't put a semicolon at the end of one of your variables/functions inside loop()

int led_rojo1=13;
int led_amarillo1=12;
int led_verde1=11;
int led_rojo2=5;
int led_amarillo2=4;
int led_verde2=3;
int encendido=1;
void setup()
{
  pinMode(led_rojo1, OUTPUT);
  pinMode(led_amarillo1, OUTPUT);
  pinMode(led_verde1, OUTPUT);
  pinMode(led_rojo2, OUTPUT);
  pinMode(led_amarillo2, OUTPUT);
  pinMode(led_verde2, OUTPUT);
}
void loop()
{
  digitalWrite(led_verde2, LOW);
  digitalWrite(led_rojo1, HIGH);
  digitalWrite(led_verde2, HIGH);
  delay(2000);
  digitalWrite(led_verde2, LOW);
  delay(2000);
  digitalWrite(led_amarillo2, HIGH);
  delay(2000);
  digitalWrite(led_amarillo2, LOW);
  digitalWrite(led_rojo1, LOW);
  delay(2000);
  digitalWrite(led_verde2, LOW);
  digitalWrite(led_verde1, HIGH)
   }

You forgot a semicolon after digitalWrite(led_verde1, HIGH) (last line before closing bracket of loop())

missing ;

I have just published the code, a semicolon is missing, but I keep getting errors

And there you go!

What do you mean? Yes, a semicolon is missing. That is the problem.

I don't see that error now, but the traffic light color order is still wrong, that's what I was referring to.

Well, Consider: the last statement in loop is immediately followed by the first statement in loop. That's how it works. So microseconds after you set your leds, you set them differently.

1 Like

I'll try that, ty

Try what? I only pointed out your error, I didn't suggest a solution. It's your assignment.

Hint: Add another delay() somewhere.

2 Likes

We're not being cruel, by the way. Some here will do your assignment for you, and some will try to get you to think. Which approach is more likely to result in you learning anything? I vote for the latter.

2 Likes

Of course! I completely understand what you are saying. The truth is that I prefer to think before having everything served. I resorted to ask in this forum because my teacher does not answer my e-mails, and he does not help me at all. But what I want is to learn, I am very interested in this, so I agree with you.

(Sorry if I have written something wrong, I don't speak much English).

2 Likes

Good to hear that you've come here for help. It shows you're resourceful. Who knows, your instructor may be trying to encourage that by not being too accessible.
If you need to continue with problems on this assignment, please remain within this thread, rather than posting new topics. It's just the way we do things around here.

2 Likes

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.