Hey folks, struggling a bit to get my head around C.
So I have a program to use the millis command to make an LED flash say 20mS on every second. What I would love to do, is produce a beacon so that the light flashes two or three times for X milliseconds every second, or whenever.
I just can't see how to change the delay from say, one second, to 50ms betweenflashes then back to one second again.
Can someone help please?
*Ignore the 2nd LED for now, just want the ability to alternately change "off duration" for now without significantly changing the code.
So I have a program to use the millis command to make an LED flash say 20mS on every second. What I would love to do, is produce a beacon so that the light flashes two or three times for X milliseconds every second, or whenever.
I just can't see how to change the delay from say, one second, to 50ms betweenflashes then back to one second again.
Can someone help please?
*Ignore the 2nd LED for now, just want the ability to alternately change "off duration" for now without significantly changing the code.
Code:
const int LEDpin = 1;
const int LEDpin1 = 2;
const long onDuration = 60;//
const long onDuration1 = 1500;//
const long offDuration = 1000;//
const long offDuration1 = 25;//
int LEDState =HIGH;// initial state of LED
int LEDState1 =HIGH;// initial state of LED
long rememberTime=0;// this is used by the code
long rememberTime1=0;// this is used by the code
void setup() {
pinMode(LEDpin,OUTPUT);// define LEDpin as output
digitalWrite(LEDpin,LEDState);// set initial state
pinMode(LEDpin1,OUTPUT);// define LEDpin as output
digitalWrite(LEDpin1,LEDState1);// set initial state
}
void loop() {
// Robojax LED blink with millis()
if( LEDState ==HIGH )
{
if( (millis()- rememberTime) >= onDuration){
LEDState = LOW;// change the state of LED
rememberTime=millis();// remember Current millis() time
}
}
else
{
if( (millis()- rememberTime) >= offDuration){
LEDState =HIGH;// change the state of LED
rememberTime=millis();// remember Current millis() time
}
}
digitalWrite(LEDpin,LEDState);// turn the LED ON or OFF
}