I'm trying to set a time limit on how long an LED blinks. Ultimately I'll use it for something more complicated, but being a N00b I thought I'd tackle it one piece at a time.
int ledPin = 13; // LED connected to digital pin 13
int Cutout // Cutout time
void setup() // run once, when the sketch starts
{
pinMode(ledPin, OUTPUT); // sets the digital pin as output
}
void loop() // run over and over again
{
digitalWrite(ledPin, HIGH); // sets the LED on
delay(1000); // waits for a second
digitalWrite(ledPin, LOW); // sets the LED off
delay(1000); // waits for a second
Cutout (1000 * 60 * 10) // cut out in 10 minutes - this is the number of milliseconds to cutout – 1000 is ms per second, 60 is mins per second, 10 is number of minutes
unsigned long startTime = millis();
if( millis() – startTime > Cutout) // check if CUTOUT ms has elapsed since motor started
break; {
digitalWrite(ledPin, LOW); // LED is off
}
}
I keep getting and error when I compile:
error: stray '' in program In function 'void loop()':
Cutout (1000 * 60 * 10) // cut out in 10 minutes - this is the number of milliseconds to cutout – 1000 is ms per second, 60 is mins per second, 10 is number of minutes
if( millis() – startTime > Cutout) // check if CUTOUT ms has elapsed since motor started
Both of these lines contain a non-ASCII character that looks like a dash when cut/pasted but shows up as a black rectangle in the browser. The first instance is in a comment, but the second is in an 'if' statement. I suspect this is the source of your problem!
As for this code:
if( millis() – startTime > Cutout) // check if CUTOUT ms has elapsed since motor started
break; {
digitalWrite(ledPin, LOW); // LED is off
}
There's a break keyword with no enclosing for, while, do or switch statement. Are you sure that's what you wanted here? Remember that the loop function executes repeatedly, for ever. You can't break out of that infinite loop, but you can make the execution stop by writing your own infinite loop inside the loop function.
I started tweaking your code and as the clock here shows 0039 and I've got nothing better to do with my time and insomnia I figured I might as well sit until it compiles. It is untested, but should set ledPin HIGH, then LOW after ten seconds.
#define ledPin 13
int Cutout = (1000 * 60 * 10);
unsigned long startTime = 0;
I changed both of those "dashes" to dashes. That's the right thing to do, yes?
It still won't compile. Same error.
Ultimately I want it to "Look for This Situation. If that situation happens for 10 minutes, Do This Thing. If the situation changes before 10 minutes, keep looking."