LCD library problem


a simple program turn on led when there interrupt ("rising") signal on pin d2 (when pushbutton connected) on mega 2560, timer counts 180 secs , turns off led , stays off until next interrupt, works perfect until decided use lcd display messages. added lcd statement loop() routine, led goes on on rising shuts off right away, counter continues 180 though, led should hjave stayed on until counter due. why lcd statement shutting off led when conditions in while statement meet?

all works fine until line:

lcd.setcursor(0,0);

 is added in loop routine, single line trashes , wont led led stay on time of counter. added serial.print statement , able see counter decrementing apparently state of d2 pin affected "lcd" line.

any clues?

thanks



//



#include <liquidcrystal.h>
#include <eeprom.h>

// global variables
byte seconds_pass = 0;
byte stat_tx = eeprom.read(101);
byte tta = eeprom.read(100);

void setup(){           
//
            lcd.begin(16, 2);
      
       pinmode(ptt_pin, output);
       pinmode(cor_pin, input);
//                   
           
           
       lcd.clear();
       lcd.setcursor(0,0);
            lcd.print("  control  ");
            lcd.setcursor(0,1);
            lcd.print("  active");
//
//
 // enable timer #5 1 one hz.
             cli(); // 
              tccr1a = 0; // 
              tccr1b = 0; // 
              tcnt1 = 0; // 
              ocr1a = 15624; 
              tccr1b |= (1 << wgm12);   
              tccr1b |= (1 << cs12) | (1 << cs10);   
              timsk1 |= (1 << ocie1a);
             sei(); // 
//
//  define isr
attachinterrupt(0,isr0,rising); 
//
//     ************* end of setup routine **********
}
//
//   timer interrupt routine
isr(timer1_compa_vect){
 
      seconds_pass++;  // increase variable each second                               
   
       }

//
void loop(){
               
                 
             while(stat_tx == 1 && digitalread(cor_pin) == true && seconds_pass <= tta) {
//                       
                    lcd.setcursor(0,0);
                         lcd.setcursor(0,1);
                         lcd.print("led off in ");
                         lcd.print(tta - seconds_pass);
                         lcd.print(" secs  ");
                      }       
//                   
                   lcd.setcursor(0,0);  // <<<<<<<< bug <<<<<<<<<<<<<<<<<<<
                   
               
                     
                     seconds_pass = 0; // avoid overflow of variable (reset 0).
                     porta = b00000000;  // turn off led.
                             
             

}
// ---------------------------------------------------------------------------------------------------
//
void isr0(){ // isr int 0 on d2
             
             
             if(debounce(cor_pin) == high){
             
             
             porta = b00001000; // activate ptt                     
             seconds_pass = 0;       
             }
}

//

boolean debounce(byte pin)
{
  boolean state;
  boolean previousstate;

  previousstate = digitalread(pin);          // store switch state
  for(int counter=0; counter < debouncedelay; counter++)
  {
      delaymicroseconds(1000);                  // wait 1 millisecond
      state = digitalread(pin);  // read pin
      if( state != previousstate) //
      {
         counter = 0; // reset counter if state changes
         previousstate = state;  // , save current state
      }
  }     
  return state;   
}

is whole sketch ?


Arduino Forum > Using Arduino > Programming Questions > LCD library problem


arduino

Comments

Popular posts from this blog

invalid use of void expresion in FlexiTimer2 library

error: a function-definition is not allowed here before '{' token

LED Strip Code