Can some explain some code, so that if I wanted to output temperature using a thermistor onto an LCD every 3 seconds using a RTC with an interupt?
Currently Im using a mod (%) function and multiple if statements but I think that an interupt so that the arduino does the temperature function at regular intervals (3 seconds) would be far better
if(t.sec%10==0 && tempfunc()<30){ // Do this if statement when the time is at an interval of 10 sec AND the temp is less than 30 deg C run this function
lcd.setCursor(0,0); // Sets the location at which subsequent text written to the LCD will be displayed, first line, start
lcd.print("Temp: "); // Prints string “Temp: " on the LCD
lcd.print(tempfunc()); // Prints the distance value from the sensor using temperature function
lcd.print(” C "); // Prints string "C " on the LCD
}
I want an interupt to interupt my code and run the function below when the time is a multiple of 10 basically.
lcd.setCursor(0,0); // Sets the location at which subsequent text written to the LCD will be displayed, first line, start
lcd.print("Temp: "); // Prints string “Temp: " on the LCD
lcd.print(tempfunc()); // Prints the distance value from the sensor using temperature function
lcd.print(” C "); // Prints string "C " on the LCD
}
output temperature using a thermistor onto an LCD every 3 seconds
Why complicate things by using an interrupt ?
You will not be able to print to the LCD in the ISR because that uses interrupts and they are disabled when in an ISR. The best that you can do is to set a flag to indicate that 3 seconds has passed and respond to it in loop() so you might just as well test for 3 seconds elapsing in loop() (or a function called for it) in the first place
I am required to run an interupt, it would be less complicated if I could do it my way.
You can defo program this, this way! I genuinely don't understand how the interupt function works, would you explain it to me, ignore the LCD etc. just treat that as a function, say LCDfunc and show me how an interrupt works please
When the interrupt occurs the program immediately stops what it is doing and runs the code in the Interrupt Service Routine . When that is finished the program returns to the place in the program where it was when the interrupt occurred and executes the next instruction after the one that it was executing when the ISR occurred
Which is it?
"I think that an interupt so that the arduino does the temperature function at regular intervals (3 seconds) would be far better"
or
"I am required to run an interupt"