0

Whenever I upload the following program I am getting error message showing "expected initializer before interval".

Kindly Help me to solve out this probleme.

const byte button=2;
const byte LED=10;
bool blinking =false;//defines when blinking should occur
unsigned long blink Interval=250;// number of milliseconds for blink
unsigned long currentMillis;// variables to track millis()
unsigned long previousMillis;
void setup()
{
 pinMode(button,INPUT);
 pinMode(LED,OUTPUT);
}
void loop()
{
 // this code blinks the LED
 if(blinking) {
 currentMillis =millis();// better to store in variable, for less jitter
 if((unsignedlong)(currentMillis-previousMillis) >=blinkInterval) { // enough time passed yet?
 digitalWrite(LED,!digitalRead(LED)); // shortcut to toggle the LED
 previousMillis =currentMillis;// sets the time we wait "from"
 }
 } else {
 digitalWrite(LED,LOW); // force LED off when not blinking
 }
 int reading=digitalRead(button);
 delay(50); // crude de-bouncing
 if(reading==LOW) // buttons with pull-up are pressed when LOW
 { blinking =true; }// start blinking
 else
 { blinking =false; }// stop blinking
}
asked Dec 27, 2017 at 8:42

2 Answers 2

3

It is blinkInterval, not blink Interval. You have an space in the name in the declaration:

unsigned long blinkInterval=250; // number of milliseconds for blink
// ....
if((unsigned long)(currentMillis-previousMillis) >= blinkInterval) { 
answered Dec 27, 2017 at 8:52
4
  • @Josephazim. That's not a problem; that's your code. When button goes HIGH, you put blinking=false. You have to introduce a waiting time there, but that is a new problem. Commented Dec 27, 2017 at 9:14
  • Thanks!It worked as you suggest but now my problem is that when I keep holding the button led is blinking and when I release the button it stop.I want it to be when I hold the push button for 5 sec, then led should start blinking for 10 minute or according to the certain time.Kindly help me to solve this problem. Commented Dec 27, 2017 at 9:54
  • @Josephazim Check out my answer. It will helpful for you. Commented Dec 27, 2017 at 10:51
  • @NickGammon I think you have to check this comment section. I answered according to that problem. Commented Dec 28, 2017 at 7:47
0

The fully working sketch

const byte button=2; 
const byte LED=10; 
bool blinking =false;
unsigned long blinkInterval=250; 
unsigned long currentMillis; 
unsigned long previousMillis; 
void setup()
{
 pinMode(button,INPUT);
 pinMode(LED,OUTPUT);
}
void loop()
{
 if(blinking) {
 currentMillis =millis();
 unsigned long blinkInterval=100;
 if((unsigned long)(currentMillis-previousMillis) >= blinkInterval) { 
 digitalWrite(LED,!digitalRead(LED)); LED
 previousMillis =currentMillis;
 }
 } else {
 digitalWrite(LED,LOW); 
 }
 int reading=digitalRead(button);
 delay(100); 
 if(reading==LOW) 
 { blinking =true; }
 else
 { blinking =false; }
}
VE7JRO
2,51519 gold badges27 silver badges29 bronze badges
answered Oct 31, 2019 at 14:12

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.