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
}
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) { 
| improve this answer | |
  • @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. – user31481 Dec 27 '17 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. – Josephazim Dec 27 '17 at 9:54
  • @Josephazim Check out my answer. It will helpful for you. – Hasan Dec 27 '17 at 10:51
  • @NickGammon I think you have to check this comment section. I answered according to that problem. – Hasan Dec 28 '17 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; }
}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.