Help me please, it was about 4 led blink with 5 seconds interval

Hello! We are tasked to make a 4 LED blink with 5 seconds interval. Means 2 led blink together with seconds interval then the 2 will blink. I don't know what code I need to make. I'm using Arduino uno board. Please send me a code
advance tysm :heart:
ps. it's rush

Welcome to the forum

This forum works by providing help to users who have a problem with code that they have written

So, what have you written so far ?

When is our assignment due to be handed in ?

You just explained what the code is expected to do. :thinking:


The way it works here is you write the code . . . if you have programming and/or hardware questions, we can try to answer them.

the deadline is tomorrow

So what have you written so far ?

I don't know how to make codes

You obviously have not been listening in class

Even if anyone were to offer to "send you a code" I'm not sure that description even makes sense. You should draw it out as a timeline perhaps, with time increasing from left to right and a line for each led showing "humps and dips" for the ons and offs.

Something like this, for each led, and of course with the lengths of each section shown:

I've read your description a few more times. Does it simply mean that for the first 5 seconds leds 1 and 2 are on together with 3 and 4 off; then for next 5 seconds 1 and 2 are off with 3 and 4 on; repeat?

If so, or even if that's not exactly what you want, look at the blink example in the ide. Add a few more leds, change the times, voila!

it's not working

const int ledPin = LED1 = 13;
const int ledPin = LED2 = 12;
const int ledPin = LED3 = 11;
const int ledPin = LED4 = 10;

int ledState = LOW; // ledState used to set the LED
unsigned long previousMillis = 2; // will store last time LED was updated
const long interval = 5000; // interval at which to blink (milliseconds)

void setup() {
pinMode(LED1,OUTPUT);
pinMode(LED2,OUTPUT);
pinMode(LED3,OUTPUT);
pinMode(LED4,OUTPUT);
}
void loop() {
unsigned long currentMillis = millis(5000);
previousMillis = currentMillis; 1000

(ledState = LOW) {
ledState = HIGH;
} else {
ledState = LOW;
} else {
ledState = HIGH;
} {
digitalWrite(LED1,LOW); // turn the LED on (HIGH is the voltage level)
delay(5000); // wait for a second
digitalWrite(LED2,HIGH); // turn the LED off by making the voltage LOW
delay(1000);
digitalWrite(LED3,LOW);
delay(5000);
digitalWrite(LED4,HIGH);
delay(1000);// wait for a second
}
check if that's correct,

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 </> icon above the compose window) to make it easier to read and copy for examination

unsigned long currentMillis = millis(5000);

What do you think this does ?

previousMillis = currentMillis; 1000

and this ?

(ledState = LOW) {

was there meant to be an if in there somewhere and do you understand the difference between = and == ?

Why are you mixing millis() timing and delay() in the same sketch ?

You seem to be trying to mix the techniques of blink with delay and blink without delay. Unless your assignment requires you to do this without delay, I would stick with the simpler (but probably ok for now) approach with delay().

So remove all the blink without delay related stuff.

Hello kafe_crexi
I´m not able to understand your task describtion, too
Either take some time and describe the desired functionality of the sketch in simple words and this very simple and short form or publish the task sheet provided by your teacher.

Have a nice day and enjoy coding in C++.
Дайте миру шанс!

It's not correct because it won't compile. Here is what I think you might have meant by what you wrote:

const int  LED1 = 13;
const int  LED2 = 12;
const int  LED3 = 11;
const int  LED4 = 10;

void setup()
{
  pinMode(LED1, OUTPUT);
  pinMode(LED2, OUTPUT);
  pinMode(LED3, OUTPUT);
  pinMode(LED4, OUTPUT);
}

void loop()
{
  digitalWrite(LED1, HIGH);
  delay(5000);
  digitalWrite(LED1, LOW);

  digitalWrite(LED2, HIGH);
  delay(5000);
  digitalWrite(LED2, LOW);

  digitalWrite(LED3, HIGH);
  delay(5000);
  digitalWrite(LED3, LOW);

  digitalWrite(LED4, HIGH);
  delay(5000);
  digitalWrite(LED4, LOW);
}

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