Hello,
I am trying to program Arduino to turn a laser ON/OFF for a desired amount of time as well as change the frequency of the laser when ON; if needed. Say I want to the laser to be OFF for 5 minutes, next turn ON for 10 minutes at 10Hz after the 5 minutes of being OFF is completed, then turn back off. I just want to be able to leave the room and the code completes as mentions but I am having trouble doing this. The laser just turns on and stays on. Thanks for the help in advance!
// These variables store the flash pattern
// and the current state of the LED
int ledPin = 13; // the number of the LED pin
int ledState = LOW; // ledState used to set the LED
unsigned long previousMillis = 0; // will store last time LED was updated
long OnTime = 10; // milliseconds of on-time (frequency)
long OffTime = 10; // milliseconds of off-time (frequency)
int StageON = 1; // minutes on laser
int StageOFF = 1; //minutes off laser
int starttime;
void setup()
{
// set the digital pin as output:
pinMode(ledPin, OUTPUT);
pinMode(12, OUTPUT);
StageON = 60*1000;
StageOFF = 60*1000;
}
void loop(){
{
{
starttime = millis();
do {
(digitalWrite (ledPin, LOW));
} while (millis()- StageOFF <= 1) ; // Turn off laser for desired amount of time
do {
(digitalWrite (ledPin, HIGH));
} while (millis() - StageON > 10) ;// Turn on laser for desired amount of time
}
unsigned long currentMillis = millis();
if ((ledState == HIGH) && (currentMillis - previousMillis >= OnTime)) // check to see if it's time to change the state of the LED
{
ledState = LOW; // Turn it off
if (ledState == LOW)
{
digitalWrite(12, HIGH);
}
previousMillis = currentMillis; // Remember the time
digitalWrite(ledPin, ledState); // Update the actual LED
}
else if ((ledState == LOW) && (currentMillis - previousMillis >= OffTime))
{
ledState = HIGH; // turn it on
previousMillis = currentMillis; // Remember the time
digitalWrite(ledPin, ledState); // Update the actual LED
if (ledState == HIGH) {
digitalWrite( 12, LOW);
}
}
}
}