My application is based on time totalizer. It will turn on the fan when nextion's START button is pressed and STOP when the predefined period is over. Again if i pressed the START it will start counting from where it stopped last time. I used timer for the counting but it will not getting trigger by the START button.
Any idea..??
I used timer for the counting but it will not getting trigger by the START button.
Do you think that it might help if you posted the code that you are having problems with ?
NexButton b0 = NexButton(0,2,"b0");
NexNumber n0 = NexNumber(0,5,"n0");
NexNumber n1 = NexNumber(0,6,"n1");
NexText t2 = NexText(0,4,"t2");
NexTouch*nex_listen_list[]={&b0,NULL};
volatile unsigned long sec=0;
volatile unsigned long Min;
volatile int count=0;
volatile int Start=0;
void setup()
{
nexInit();
Serial.begin(9600);
b0.attachPop(b0PopCallback,&b0);
// initialize timer1
noInterrupts(); // disable all interrupts
TCCR1A = 0;
TCCR1B = 0;
TCNT1= 0;
OCR1A = 62500; // compare match register 16MHz/256/2Hz
TCCR1B |= (1 << WGM12); // CTC mode
TCCR1B |= (1 << CS12); // 256 prescaler
TIMSK1 |= (1 << OCIE1A); // enable timer compare interrupt
}
void loop()
{
nexLoop(nex_listen_list);
if (Start== HIGH) //start the timer intterupt for specific time
{
interrupts();
while(count<120)
{
n0.setValue(Min);
t2.setText(":");
n1.setValue(sec);
}
count=0;
}
noInterrupts(); //after desired time paused the timer
Start=0;
n0.setValue(Min);
t2.setText(":");
n1.setValue(sec);
}
ISR(TIMER1_COMPA_vect) // timer compare interrupt service routine
{
sec=sec+1;
count=sec;
if(sec>59)
{
Min++;
}
sec=0;
}
void b0PopCallback(void*ptr) //set the flag to check the input switch
{
Start++;;
}
snehalrudra:
I used timer for the counting.
Why? It makes your program very opaque and I don't see a need for it given your requirements. millis will do what you need and you won't have to dig into data sheets to be able to read or debug your code.