Help...!!!Push button not working on delay larger than 200 millsec!!!


hello new form. trying different led patterns when push button pressed.the below sketch used switch case. when button pressed change between different led patterns switch cases. works delay time lower 200 mill sec.if delay time more 200millsec ,push button  relay hit or miss because going in delay state.that means sketch not responsive thought.
this trying accomplish ,as press button should change next switch case irrespective of delay time...can 1 me please.. totally appreciated.thanks


code: [select]
int led1 = 9;
int led2 = 8;
int buttonpin = 11;
int val = 0;
int sequence = 1;


void setup() {                
 pinmode(led1, output);
 pinmode(led2, output);
 pinmode(buttonpin, input);
   
}


void loop()                    
{

       val = digitalread(buttonpin);
       if(val == low)
       {
           if(sequence == 2)
           {
              sequence = 1;
           } else
               {
                 sequence++;
               }
               delay(50);  
       }
                           
        switch(sequence)
                {
                    case 1:
                    blink1();
                    break;
                    case 2:
                    blink2();  
                    break;
                   
                }
                           
                           
}

void blink1() {
 int delaytime =200;
 digitalwrite(led1, high);  
 button_delay(delaytime, buttonpin);              
 digitalwrite(led1, low);    
 button_delay(delaytime, buttonpin);

 digitalwrite(led2, high);  
 button_delay(delaytime, buttonpin);              
 digitalwrite(led2, low);    
 button_delay(delaytime, buttonpin);  
}

void blink2() {
 int delaytime = 500;
 digitalwrite(led1, high);  
 button_delay(delaytime, buttonpin);              
 digitalwrite(led1, low);    
 button_delay(delaytime, buttonpin);

 digitalwrite(led2, high);  
 button_delay(delaytime, buttonpin);              
 digitalwrite(led2, low);    
 button_delay(delaytime, buttonpin);    
}


void button_delay(int msec, int btnpin)  
{
 int btnstate = 0;      
 btnstate = digitalread(btnpin);
 if(btnstate == high)
 {
   delay(msec);
 }
 
}

you didn't read "how use forum" sticky did you. read , modify post use code tags.

then @ blink without delay in arduino's ide examples.
then read state machines
this 1 such link
http://www.thebox.myzen.co.uk/tutorial/state_machine.html


Arduino Forum > Using Arduino > Programming Questions > Help...!!!Push button not working on delay larger than 200 millsec!!!


arduino

Comments

Popular posts from this blog

Connecting Raspberry Pi 2 to P10(1R)-V706 LED Dot Matrix - Raspberry Pi Forums

TypeError: <unknown> is not a numpy array - Raspberry Pi Forums

datso and removing imagetitle - Joomla! Forum - community, help and support