Can I use another bracket inside a delay bracket?(Solved:nikoexcited:)

Im tryna make a pedastrian traffic system where the traffic green led will blink for a certain time
Edit: new code

int button = 2;
int pedestrian_light_red = 3;
int pedestrian_light_green = 4;
int traffic_light_red = 5;
int traffic_light_yellow = 6;
int traffic_light_green = 7;
void setup() {
  // put your setup code here, to run once:
  pinMode(button, INPUT);
  pinMode(pedestrian_light_red, OUTPUT);
  pinMode(pedestrian_light_red, OUTPUT);
  pinMode(traffic_light_red, OUTPUT);
  pinMode(traffic_light_yellow, OUTPUT);
  pinMode(traffic_light_red, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  if (digitalRead(button) == HIGH) {
    delay(10000);
    digitalWrite(traffic_light_green, LOW);
    digitalWrite(traffic_light_yellow, HIGH);
    delay(2000);
    digitalWrite(traffic_light_yellow, LOW);
    digitalWrite(traffic_light_red, HIGH);
    delay(1000);
    digitalWrite(pedestrian_light_red, HIGH);
  } else {
    digitalWrite(traffic_light_green, HIGH);
    digitalWrite(pedestrian_light_red, HIGH);
  }
}

Welcome to the forum

Please do not post pictures of code

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the < CODE/ > icon above the compose window) to make it easier to read and copy for examination

Please post your full sketch, using code tags when you do

Posting your code using code tags prevents parts of it being interpreted as HTML coding and makes it easier to copy for examination

In my experience the easiest way to tidy up the code and add the code tags is as follows

Start by tidying up your code by using Tools/Auto Format in the IDE to make it easier to read. Then use Edit/Copy for Forum and paste what was copied in a new reply. Code tags will have been added to the code to make it easy to read in the forum thus making it easier to provide help.

It is also helpful to post full error messages in code tags as it makes it easier to scroll through them and copy them for examination

To post the error message, click the "COPY ERROR MESSAGES" button in the IDE, paste the copied messages in a reply here, select all of it and click the < CODE > icon above the reply editor to add the code tags and then save the reply

It is not clear from you description what exactly you want to do with delay() so please explain your problem better

I note that the code you posted will not compile. Look at line 22 for example. Which pin are you trying to set LOW ?

  • Always show us a good schematic of your proposed circuit. Show us good images of your ‘actual’ wiring. Give links to components.

  • This does nothing delay()

  • What are you doing here digitalWrite( , LOW);

For many Arduino boards, digital pins 0 and 1 should be left for communication only.

#define BUTTON_PIN 0
#define PEDESTRIAN_LED_RED 1

Pin 1 and Pin 0 are reserved for serial communication. Do not use these pins with Arduino Uno/Nano R3.

please, please never ever again post pictures of text... Not only they are not readable nor usable directly for copy&paste but they use up lots of storage and internet bandwidth which contributes to polluting the planet.

➜ do your part and do yourself a favour and please read How to get the best out of this forum and modify your post accordingly (including code tags and necessary documentation for your ask).

How do I post schematics

Copy and paste or drag and drop the image right here where you type your text.

(thanks for pasting the code as text and getting rid of the image - which means you knew how to attach an image...)

To post images etc. you need trust level 1, you can get there by:

  • Entering at least 5 topics
  • Reading at least 30 posts
  • Spend a total of 10 minutes reading posts

Users at trust level 1 can...

  • Use all core Discourse functions; all new user restrictions are removed
  • Send PMs
  • Upload images and attachments

https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum/679966

talks about that. Then, top right corner of forum pages, you have “Search forum“.

Yes you can use brackets inside delay, but I think you were looking for something like this:

void loop() {
  // put your main code here, to run repeatedly:
  if (digitalRead(button) == HIGH) {
    delay(10000);

    // blink green light for 5s
    for (int i = 0; i < 5; i++) {
      digitalWrite(traffic_light_green, HIGH);
      delay(500); 
      digitalWrite(traffic_light_green, LOW);
      delay(500); 
    }

    digitalWrite(traffic_light_yellow, HIGH);
    delay(2000);
    digitalWrite(traffic_light_yellow, LOW);
    digitalWrite(traffic_light_red, HIGH);
    delay(1000);
    digitalWrite(pedestrian_light_red, HIGH);
  } else {
    digitalWrite(traffic_light_green, HIGH);
    digitalWrite(pedestrian_light_red, HIGH);
  }
}

Yoo thx, btw How does it work

What you mean?
It's repeating green blink for 5 times before going off.
Adjust the times and repeats as you prefer...

I mean this one
for (int i = 0; i < 5; i++) {

i starts from zero and i++ is increasing it every cycle. < 5 is the limit, if you want 10 blinks put
i < 10

ohh, I get it now:nikoexcited:(Also, <= 20 = 20 blinks?)

Here da schematic(I hope I won't get send to the banland again)

Any reason why you put your wires straight over the resistors?
And why you put everything on 1/10th of the board?
It is impossible to follow...

You code is missing the pedestrian green and red is used twice.

I'm not shore if I fixed it

int button = 2;
int pedestrian_light_red = 3;
int pedestrian_light_green = 4;
int traffic_light_green = 5;
int traffic_light_yellow = 6;
int traffic_light_red = 7;
void setup() {
  // put your setup code here, to run once:
  pinMode(button, INPUT);
  pinMode(pedestrian_light_red, OUTPUT);
  pinMode(pedestrian_light_green, OUTPUT);
  pinMode(traffic_light_red, OUTPUT);
  pinMode(traffic_light_yellow, OUTPUT);
  pinMode(traffic_light_green, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  if (digitalRead(button) == HIGH) {
    delay(10000);
    for(int i = 0; i <= 20; i++){
      digitalWrite(traffic_light_green, HIGH);
      delay(500);
      digitalWrite(traffic_light_green, LOW);
      delay(500);
    }
    digitalWrite(traffic_light_green, LOW);
    digitalWrite(traffic_light_yellow, HIGH);
    delay(2000);
    digitalWrite(traffic_light_yellow, LOW);
    digitalWrite(traffic_light_red, HIGH);
    delay(1000);
    digitalWrite(pedestrian_light_green, HIGH);
    digitalWrite(traffic_light_red, LOW);
  } else {
    digitalWrite(traffic_light_green, HIGH);
    digitalWrite(pedestrian_light_red, HIGH);
  }
}