I'm using struct now but i still unable to use only one function flashled(led_id) to pass argument of the led id i want to blink !!
I should never stop programming 22 years ago :-[
long time = 0;
typedef struct BlinkPin{
byte ledpin;
unsigned int ledON;
unsigned int ledOFF;
unsigned long timeON;
unsigned long timeOFF;
boolean state;
};
BlinkPin led1 = {10,25,1000,0,0,0};
BlinkPin led2 = {11,800,500,0,0,0};
BlinkPin led3 = {12,25,250,0,0,0};
void setup(){
Serial.begin(38400);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
}
void loop(){
flashled1();
flashled2();
flashled3();
}
void flashled1() {
time = millis();
if (led1.state == HIGH) {
if (time >= led1.timeOFF) {
led1.state = LOW;
Serial.print(led1.state);
digitalWrite(led1.ledpin, led1.state);
led1.timeON = led1.timeOFF + led1.ledOFF;
}
}
else {
if (led1.state == LOW){
if (time >= led1.timeON) {
led1.timeON = millis();
led1.state = HIGH;
Serial.print(led1.state);
digitalWrite(led1.ledpin, led1.state);
led1.timeOFF = led1.timeON + led1.ledON;
}
}
}
}
void flashled2() {
time = millis();
if (led2.state == HIGH) {
if (time >= led2.timeOFF) {
led2.state = LOW;
Serial.print(led2.state);
digitalWrite(led2.ledpin, led2.state);
led2.timeON = led2.timeOFF + led2.ledOFF;
}
}
else {
if (led2.state == LOW){
if (time >= led2.timeON) {
led2.timeON = millis();
led2.state = HIGH;
Serial.print(led2.state);
digitalWrite(led2.ledpin, led2.state);
led2.timeOFF = led2.timeON + led2.ledON;
}
}
}
}
void flashled3() {
time = millis();
if (led3.state == HIGH) {
if (time >= led3.timeOFF) {
led3.state = LOW;
Serial.print(led3.state);
digitalWrite(led3.ledpin, led3.state);
led3.timeON = led3.timeOFF + led3.ledOFF;
}
}
else {
if (led3.state == LOW){
if (time >= led3.timeON) {
led3.timeON = millis();
led3.state = HIGH;
Serial.print(led3.state);
digitalWrite(led3.ledpin, led3.state);
led3.timeOFF = led3.timeON + led3.ledON;
}
}
}
}
This should look like this :
flashled(led1);
flashled(led2);
flashled(led3);
void flashled(led_id) {
time = millis();
if (led_id.state == HIGH) {
if (time >= led_id.timeOFF) {
led_id.state = LOW;
Serial.print(led_id.state);
digitalWrite(led_id.ledpin, led_id.state);
led_id.timeON = led_id.timeOFF + led_id.ledOFF;
}
}
else {
if (led_id.state == LOW){
if (time >= led_id.timeON) {
led_id.timeON = millis();
led_id.state = HIGH;
Serial.print(led1.state);
digitalWrite(led_id.ledpin, led_id.state);
led_id.timeOFF = led_id.timeON + led_id.ledON;
}
}
}
}