Hi guys. First of all, thanks for the all replies and tips. I managed to learn some basics of millis, but I don't know how to do this. I had an idea, but it's not working . LEDs are on when I press, but they're not turning on and off. When I release the button, they're off. That part is working. Here's the code:
#include <Bounce2.h>
int pin[4] = {7, 6, 5, 4};
int btn = 8;
int dt = 250;
int pt = 0;
int state = LOW;
Bounce b = Bounce();
void setup() {
b.attach(btn, INPUT);
b.interval(250);
pinMode(pin[0], OUTPUT);
pinMode(pin[1], OUTPUT);
pinMode(pin[2], OUTPUT);
pinMode(pin[3], OUTPUT);
}
void loop() {
int g = digitalRead(btn);
int ct = millis();
if(g==0){
digitalWrite(pin[0],HIGH);
if(ct-pt>=dt){
pt=ct;
digitalWrite(pin[0],LOW);
}
digitalWrite(pin[1],HIGH);
if(ct-pt>=dt){
pt=ct;
digitalWrite(pin[1],LOW);
}
digitalWrite(pin[2],HIGH);
if(ct-pt>=dt){
pt=ct;
digitalWrite(pin[2],LOW);
}
digitalWrite(pin[3],HIGH);
if(ct-pt>=dt){
pt=ct;
digitalWrite(pin[3],LOW);
}
}
if(g==1){
digitalWrite(pin[0],LOW);
digitalWrite(pin[1],LOW);
digitalWrite(pin[2],LOW);
digitalWrite(pin[3],LOW);
}
}