Good evening. I am trying to make an LED turn on for 250ms and then off again for 750ms repeatedly. I have tried various methods, but with little success. The code below is my closest yet: however, after an initial blink, the LED settles into a dim glow, but I cannot see why. Any help would be appreciated.
Thank you.
James.
const int Built_in_LED = 13; // The number of the LED pin
unsigned long Currently_It_Is = millis(); // Present time
unsigned long Previously_It_Was = 0; // Time an event occurred
const long Time_to_Light_LED = 250; // Duration LED remains on
const long Time_to_Extinguish_LED = 750; // Duration LED remains off
void setup() {
pinMode(Built_in_LED, OUTPUT); // Set the digital pin as output:
digitalWrite(Built_in_LED, LOW); // Start LED turned off
Serial.begin (9600); //Initiate serial printer
}
void loop() {
if (Currently_It_Is - Previously_It_Was >= Time_to_Extinguish_LED); // Wait for 750 and then turn LED on
{
Previously_It_Was = Currently_It_Is;
digitalWrite(Built_in_LED, HIGH);
}
if (Currently_It_Is - Previously_It_Was >= Time_to_Light_LED); // Wait for 250 and then turn LED off
{
Previously_It_Was = Currently_It_Is;
digitalWrite(Built_in_LED, LOW);
}
}