1 led 3 different times, with millis Help PLS..

Hi, 
[color=#202124]when the counter is 50, [/color]digitalWrite13[color=#202124], 3 seconds open, 5 seconds close, 1second open, then off + counter = 0; This is what I want to do, I can, the code below . I am   [/color]

sorry for my bad english

int zamanBayrak ;
unsigned long gecenZaman = 0;
unsigned long zamanTut;
unsigned long sayac;

#define Led 13

void setup() {
  pinMode(Led, OUTPUT);

  Serial.begin(9600);
}

void loop() {
  
  sayac = sayac + 10;
  Serial.println(sayac);

  if (sayac >= 50)  {

     digitalWrite(13, HIGH);
    Serial.println("motor_open");

    
     zamanTut = millis();
    if (zamanBayrak == 1) {
      gecenZaman = millis();
      zamanBayrak = 0;
    }
    if (zamanTut - gecenZaman >= 3000) {
      sayac = 0;
      digitalWrite(13, LOW);
      Serial.println("motor_close");
      
    }
  }
  else {
    zamanBayrak = 1;
  }



  

}

Implement a state machine for all those open and closed states.

Check your examples in your IDE it probably has "Blink Without Delay" if not you can download it. It does basically what you want to do. There is always one more answer then given at the time.

DrDiettrich:
Implement a state machine for all those open and closed states.

I'm a rookie, can you edit my code for me?I would be grateful to you. It is very simple to delay it but it doesn't work for me, I did it with the delay code I wanted. It's very easy to do this code with delay but it doesn't work for me :frowning:
digitalWrite (13, HIGH);
delay (1000);
digitalWrite (13, LOW);
delay(5000);
digitalWrite (13, HIGH);
delay (1000);
digitalWrite (13, LOW);

What happened to the "3 seconds open" ?
Did you read the Blink Without Delay page ? Do you understand it ?

There might be 10 or 20 ways to do this.

A.
With a Finite State Machine as DrDiettrich wrote. Tutorial: The Finite State Machine | Majenko Technologies and an example by me: millis_and_finite_state_machine.ino.

B.
The sequence could be put in a table: millis_rhythm.ino.

C.
Suppose there is a millis-timer that runs every second.
seconds = 0, set pin HIGH
seconds = 3, set pin LOW
seconds = 8, set pin HIGH
seconds = 9, set pin LOW

Take a pick, which one do you like most ?

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