Hi!
Iam trying to make 4 LEDs blink simultaneously and a certain amounts of blinks fr each LED, eg. 1 LED blinks 5 times, 2 LED blinks 7 times and so on, at the same time... I've found an old thread and have been working with the suggested code and I get the LEDs to blink but they blink one by one. Is there a way for it to blink simultaneously and different amount of blinks?
Sorry for my poor english, I did my best trying to explain.
int led1 = 6;
int led2 = 2;
int led3 = 3;
int led4 = 4;
int buttonpin = 8;
bool blinking = false;
int button = 0;
void setup()
{
Serial.begin(9600);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
pinMode(buttonpin, INPUT);
}
void loop()
{
if(blinking == true) {
blink1(5, 500); // 5 is number of blinks, blinkTime is the milliseconds in each state from above: int blinkTime = 500;
blink2(7, 250);
blink3(2, 750);
blink4(8, 100);
}
button=digitalRead(buttonpin);
Serial.println(button);
if (button==HIGH){
blinking = true;
}
else{
blinking = false;
}
}
void blink1(int repeats, int time)
{
for (int i = 0; i < repeats; i++)
{
digitalWrite(led1, HIGH);
delay(time);
digitalWrite(led1, LOW);
delay(time);
}
}
void blink2(int repeats, int time)
{
for (int i = 0; i < repeats; i++)
{
digitalWrite(led2, HIGH);
delay(time);
digitalWrite(led2, LOW);
delay(time);
}
}
void blink3(int repeats, int time)
{
for (int i = 0; i < repeats; i++)
{
digitalWrite(led3, HIGH);
delay(time);
digitalWrite(led3, LOW);
delay(time);
}
}
void blink4(int repeats, int time)
{
for (int i = 0; i < repeats; i++)
{
digitalWrite(led4, HIGH);
delay(time);
digitalWrite(led4, LOW);
delay(time);
}
}