I am working on a project of blinking of led using push button without delay().The limitations of led blinking is in accordance with the no of times the push button is pressed the led should blink that many no of times(i.e,) when the push button is pressed for the first time it should blink once and when pressed 2nd time it should blink twice till number of times.Can someone please help me out in solving this.I am attaching the code. please someone help me in solving this.Thanks in advance.

int led =13;
int button= 4;
int buttonState = 0;
int count_value =0;
int prestate =0;
int ledState = LOW; 
unsigned long currentMillis;
unsigned long previousMillis = 0;       
const long interval = 1000; 

void setup() {

void loop() {
 buttonState = digitalRead(button);
 while(buttonState == 1 && prestate == 0) {
  Serial.print  ("count_value="); Serial.println(count_value);
   for(int j=0; j<=(count_value); j++)
    currentMillis = millis();
    if(currentMillis - previousMillis >= interval) {
     digitalWrite(led, !digitalRead(led));
     previousMillis = currentMillis; 
  prestate = 1;
 if(buttonState == 0) {
    prestate = 0;
  • Welcome to SE/Arduino! Please take the tour and read "How to Ask". Then come back and edit your question. What do you mean by "that didn't workout"? What do you expect exactly, and what do you get instead? What have you tried to solve it? – the busybee Feb 15 at 12:13
  • but that didn't workout is a useless description of the observed behavior ... please do not expect people to guess about what happens when you run the program – jsotola Feb 15 at 17:03
  • 1
    sorry for the inconvinence happened. I am a fresher and was not aware of how to ask questions. – Srilakshmi Feb 16 at 7:40
  • 1
    I tried solving it by resetting millis(); but couldn't reset it. – Srilakshmi Feb 16 at 7:41
  • 1
    Thanks for your help. Will check out the resources. @ZhelyazkoGrudov – Srilakshmi Feb 17 at 12:59

Your Answer

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

Browse other questions tagged or ask your own question.