Is there a limit of commands inside the ISR?
I have 20 (18x IF's and 2 other)
Trying to make a dual counter but i can only get 1 working at a time.
The general rule in an ISR is to get in, get out. Not process. So, not a limit, a commonsense approach.
That if far too many
There is no limit to the amount of code that can be put in an ISR but it should be kept to a minimum. Perhaps saving a timestamp and setting a flag to indicate that the interrupt has been triggered.
Then, based on the flag value the resulting actions are taken in the main code
It sounds like you are misusing interrupts. What makes you think that you need to use them ?
Note too that interrupts are disabled in an ISR so you cannot use functions that use interrupts such as Serial.print()
In the ideal case, the ISR should just set a global flag, declared "volatile" and exit. The main loop should do the processing.
}
ISR(TIMER1_COMPA_vect){
if(run == true){ms=ms+1;
if(ms>999){ms=0;ss=ss+1;}
if(ss>59){ss=0; mm=mm+1;}
if(mm>59){mm=0; hh=hh+1;}
}
if (bopage == 0){
if(hhbo==0 && mmbo==0 && ssbo==0 && msbo==0){
bo = 0;
}
if(bo == 1){msbo=msbo-1;
if(msbo<0){msbo=999;ssbo=ssbo-1;
if(ssbo<0){ssbo=59; mmbo=mmbo-1;}
if(mmbo<0){mmbo=59; hhbo=hhbo-1;}
if(hhbo<0){hhbo=0;}
}
//EVERYTHING WORKS UNTIL THIS POINT, DOWN FROM HERE NOT DOING THE COUNTS
if (bopage == 1) {
if(hhbo2==0 && mmbo2==0 && ssbo2==0 && msbo2==0){
bo2 = 0;
}
if(bo2 == 1){msbo2=msbo2-1;
if(msbo2<0){msbo2=999;ssbo2=ssbo2-1;
if(ssbo2<0){ssbo2=59; mmbo2=mmbo2-1;}
if(mmbo2<0){mmbo2=59; hhbo2=hhbo2-1;}
if(hhbo2<0){hhbo2=0;}
}
}
}
}
}
}
The 4 first IF's work, next part works but the last counter doesnt work, or if i comment out the second, then the last part works
if(run == true){ms=ms+1;
Is that really your code ?
Is it really necessary for all of that code to be in the ISR ? Take note of the advice given above
Are all of those variables declared volatile? This Q&A may continue for a while, if you don't post WHOLE code.
#include <SPI.h> // include SPI library
#include <Adafruit_GFX.h> // include adafruit graphics library
#include <Adafruit_PCD8544.h> // include adafruit PCD8544 (Nokia 5110) library
#define bt_1 8
#define bt_2 9
#define bt_3 10
#define bt_4 11
#define bt_5 12
#define bt_6 1
int bopage = 0;
int bo = 1;
int bo2 = 1;
int hh=7, mm=8, ss=43, ms=0;
int hhbo=0, mmbo=1, ssbo=5, msbo=0;
int tmmbo=0, tssbo=0, tmsbo=0;
int hhbo2=0, mmbo2=1, ssbo2=10, msbo2=0;
int tmmbo2=0, tssbo2=0, tmsbo2=0;
bool run = true;
// Nokia 5110 LCD module connections (CLK, DIN, D/C, CS, RST)
Adafruit_PCD8544 display = Adafruit_PCD8544(6, 5, 4, 3, 2);
void setup() {
// put your setup code here, to run once:
display.begin();
display.setContrast(45);
display.clearDisplay(); // clear the screen and buffer
display.display();
display.setTextSize(1,2);
display.setTextColor(BLACK, WHITE);
display.display();
pinMode(bt_1, INPUT_PULLUP);
pinMode(bt_2, INPUT_PULLUP);
pinMode(bt_3, INPUT_PULLUP);
pinMode(bt_4, INPUT_PULLUP);
pinMode(bt_5, INPUT_PULLUP);
pinMode(bt_6, INPUT_PULLUP);
noInterrupts(); // disable all interrupts
TCCR1A = 0; // set entire TCCR1A register to 0 //set timer1 interrupt at 1kHz // 1 ms
TCCR1B = 0; // same for TCCR1B
TCNT1 = 0; // set timer count for 1khz increments
OCR1A = 1999; // = (16*10^6) / (1000*8) - 1
//had to use 16 bit timer1 for this bc 1999>255, but could switch to timers 0 or 2 with larger prescaler
// turn on CTC mode
TCCR1B |= (1 << WGM12); // Set CS11 bit for 8 prescaler
TCCR1B |= (1 << CS11); // enable timer compare interrupt
TIMSK1 |= (1 << OCIE1A);
interrupts(); // enable
}
void loop() {
// put your main code here, to run repeatedly:
display.display();
if (digitalRead (bt_1) == 0 && run == true) { //Pause stopwatch
run = false;
delay(200);
}
if (digitalRead (bt_1) == 0 && run == false) { //Start stopwatch
run = true;
delay(200);
}
if(digitalRead (bt_6) == 0){
ms=0, ss=0, mm=0, hh=0; // Reset stopwatch
run = false;
delay(100);
}
if(digitalRead (bt_3) == 0){
if (bopage == 0){
msbo=0, ssbo=tssbo, mmbo=tmmbo, hhbo=0, bo=1; // Reset stopwatch
}
else {
msbo2=0, ssbo2=tssbo2, mmbo2=tmmbo2, hhbo2=0, bo2=1; // Reset stopwatch
}
delay(100);
}
if(digitalRead (bt_2) == 0){
if (bopage == 0){
bopage = 1;
bo = 0;
}
else {
bopage = 0;
bo2 = 1;
}
delay(100);
}
if (digitalRead (bt_4) == 0) { //+ 5s bo
if (bopage == 0){
tssbo = tssbo + 5;
if(tssbo>=60){tssbo=0;tmmbo=tmmbo+1;}
bo = 0;
mmbo = tmmbo;
ssbo = tssbo;
}
else {
tssbo2 = tssbo2 + 5;
if(tssbo2>=60){tssbo2=0;tmmbo2=tmmbo2+1;}
bo2 = 0;
mmbo2 = tmmbo2;
ssbo2 = tssbo2;
}
if (bopage == 0){
display.setCursor (60,15);
display.print((mmbo/10)%10);
display.print(mmbo%10);
display.print(":");
display.print((ssbo/10)%10);
display.print(ssbo%10);
}
if (bopage == 1) {
display.setCursor (60,30);
display.print((mmbo2/10)%10);
display.print(mmbo2%10);
display.print(":");
display.print((ssbo2/10)%10);
display.print(ssbo2%10);
}
delay(200);
}
if (digitalRead (bt_5) == 0) { //- 5s bo
if (bopage == 0){
tssbo = tssbo - 5;
if(tssbo<0 && tmmbo==0){tssbo=0, tmmbo=0;}
if(tssbo<0){tssbo=55;tmmbo=tmmbo-1;}
bo = 0;
mmbo = tmmbo;
ssbo = tssbo;
}
else {
tssbo2 = tssbo2 - 5;
if(tssbo2<0 && tmmbo2==0){tssbo2=0, tmmbo2=0;}
if(tssbo2<0){tssbo2=55;tmmbo2=tmmbo2-1;}
bo2 = 0;
mmbo2 = tmmbo2;
ssbo2 = tssbo2;
}
if (bopage == 0){
display.setCursor (60,15);
display.print((mmbo/10)%10);
display.print(mmbo%10);
display.print(":");
display.print((ssbo/10)%10);
display.print(ssbo%10);
}
else {
display.setCursor (60,30);
display.print((mmbo2/10)%10);
display.print(mmbo2%10);
display.print(":");
display.print((ssbo2/10)%10);
display.print(ssbo2%10);
}
delay(200);
}
display.setCursor(0, 0);
display.print("Run:");
if (bopage == 0){
display.setCursor (0, 15);
display.print("BO 1: <-");
display.setCursor (0, 30);
display.print("BO 2:");
}
else {
display.setCursor (0, 15);
display.print("BO 1: ");
display.setCursor (0, 30);
display.print("BO 2: <");
}
//Runtime timer
display.setCursor (30,0);
display.print((hh/10)%10);
display.print(hh%10);
display.print(":");
display.print((mm/10)%10);
display.print(mm%10);
display.print(":");
display.print((ss/10)%10);
display.print(ss%10);
//if (bopage == 0){
display.setCursor (40, 15);
display.print((mmbo/10)%10);
display.print(mmbo%10);
display.print(":");
display.print((ssbo/10)%10);
display.print(ssbo%10);
//}
//else {
display.setCursor (40, 30);
display.print((mmbo2/10)%10);
display.print(mmbo2%10);
display.print(":");
display.print((ssbo2/10)%10);
display.print(ssbo2%10);
//}
}
ISR(TIMER1_COMPA_vect){
if(run == true){ms=ms+1;
if(ms>999){ms=0;ss=ss+1;}
if(ss>59){ss=0; mm=mm+1;}
if(mm>59){mm=0; hh=hh+1;}
}
if (bopage == 0){
if(hhbo==0 && mmbo==0 && ssbo==0 && msbo==0){
bo = 0;
}
if(bo == 1){msbo=msbo-1;
if(msbo<0){msbo=999;ssbo=ssbo-1;
if(ssbo<0){ssbo=59; mmbo=mmbo-1;}
if(mmbo<0){mmbo=59; hhbo=hhbo-1;}
if(hhbo<0){hhbo=0;}
}
//EVERYTHING WORKS UNTIL THIS POINT, DOWN FROM HERE NOT DOING THE COUNTS
if (bopage == 1) {
if(hhbo2==0 && mmbo2==0 && ssbo2==0 && msbo2==0){
bo2 = 0;
}
if(bo2 == 1){msbo2=msbo2-1;
if(msbo2<0){msbo2=999;ssbo2=ssbo2-1;
if(ssbo2<0){ssbo2=59; mmbo2=mmbo2-1;}
if(mmbo2<0){mmbo2=59; hhbo2=hhbo2-1;}
if(hhbo2<0){hhbo2=0;}
}
}
}
}
}
}
full code posted
"No" was the answer. Please do as the others have suggested, extricate all that from the ISR. Set a flag, do the if-nightmare when the flag gets set.
Also, when printing the "<-" it works as intended when bopage = 1, if bopage = 0, then the <- stays in on the display as if bopage was 0 & 1
Okay. {changes channel. Next participant!}
Code after using the Autoformat command in the IDE (CTRL-T):
#include <SPI.h> // include SPI library
#include <Adafruit_GFX.h> // include adafruit graphics library
#include <Adafruit_PCD8544.h> // include adafruit PCD8544 (Nokia 5110) library
#define bt_1 8
#define bt_2 9
#define bt_3 10
#define bt_4 11
#define bt_5 12
#define bt_6 1
int bopage = 0;
int bo = 1;
int bo2 = 1;
int hh = 7, mm = 8, ss = 43, ms = 0;
int hhbo = 0, mmbo = 1, ssbo = 5, msbo = 0;
int tmmbo = 0, tssbo = 0, tmsbo = 0;
int hhbo2 = 0, mmbo2 = 1, ssbo2 = 10, msbo2 = 0;
int tmmbo2 = 0, tssbo2 = 0, tmsbo2 = 0;
bool run = true;
// Nokia 5110 LCD module connections (CLK, DIN, D/C, CS, RST)
Adafruit_PCD8544 display = Adafruit_PCD8544(6, 5, 4, 3, 2);
void setup() {
// put your setup code here, to run once:
display.begin();
display.setContrast(45);
display.clearDisplay(); // clear the screen and buffer
display.display();
display.setTextSize(1, 2);
display.setTextColor(BLACK, WHITE);
display.display();
pinMode(bt_1, INPUT_PULLUP);
pinMode(bt_2, INPUT_PULLUP);
pinMode(bt_3, INPUT_PULLUP);
pinMode(bt_4, INPUT_PULLUP);
pinMode(bt_5, INPUT_PULLUP);
pinMode(bt_6, INPUT_PULLUP);
noInterrupts(); // disable all interrupts
TCCR1A = 0; // set entire TCCR1A register to 0 //set timer1 interrupt at 1kHz // 1 ms
TCCR1B = 0; // same for TCCR1B
TCNT1 = 0; // set timer count for 1khz increments
OCR1A = 1999; // = (16*10^6) / (1000*8) - 1
//had to use 16 bit timer1 for this bc 1999>255, but could switch to timers 0 or 2 with larger prescaler
// turn on CTC mode
TCCR1B |= (1 << WGM12); // Set CS11 bit for 8 prescaler
TCCR1B |= (1 << CS11); // enable timer compare interrupt
TIMSK1 |= (1 << OCIE1A);
interrupts(); // enable
}
void loop() {
// put your main code here, to run repeatedly:
display.display();
if (digitalRead (bt_1) == 0 && run == true) { //Pause stopwatch
run = false;
delay(200);
}
if (digitalRead (bt_1) == 0 && run == false) { //Start stopwatch
run = true;
delay(200);
}
if (digitalRead (bt_6) == 0) {
ms = 0, ss = 0, mm = 0, hh = 0; // Reset stopwatch
run = false;
delay(100);
}
if (digitalRead (bt_3) == 0) {
if (bopage == 0) {
msbo = 0, ssbo = tssbo, mmbo = tmmbo, hhbo = 0, bo = 1; // Reset stopwatch
}
else {
msbo2 = 0, ssbo2 = tssbo2, mmbo2 = tmmbo2, hhbo2 = 0, bo2 = 1; // Reset stopwatch
}
delay(100);
}
if (digitalRead (bt_2) == 0) {
if (bopage == 0) {
bopage = 1;
bo = 0;
}
else {
bopage = 0;
bo2 = 1;
}
delay(100);
}
if (digitalRead (bt_4) == 0) { //+ 5s bo
if (bopage == 0) {
tssbo = tssbo + 5;
if (tssbo >= 60) {
tssbo = 0;
tmmbo = tmmbo + 1;
}
bo = 0;
mmbo = tmmbo;
ssbo = tssbo;
}
else {
tssbo2 = tssbo2 + 5;
if (tssbo2 >= 60) {
tssbo2 = 0;
tmmbo2 = tmmbo2 + 1;
}
bo2 = 0;
mmbo2 = tmmbo2;
ssbo2 = tssbo2;
}
if (bopage == 0) {
display.setCursor (60, 15);
display.print((mmbo / 10) % 10);
display.print(mmbo % 10);
display.print(":");
display.print((ssbo / 10) % 10);
display.print(ssbo % 10);
}
if (bopage == 1) {
display.setCursor (60, 30);
display.print((mmbo2 / 10) % 10);
display.print(mmbo2 % 10);
display.print(":");
display.print((ssbo2 / 10) % 10);
display.print(ssbo2 % 10);
}
delay(200);
}
if (digitalRead (bt_5) == 0) { //- 5s bo
if (bopage == 0) {
tssbo = tssbo - 5;
if (tssbo < 0 && tmmbo == 0) {
tssbo = 0, tmmbo = 0;
}
if (tssbo < 0) {
tssbo = 55;
tmmbo = tmmbo - 1;
}
bo = 0;
mmbo = tmmbo;
ssbo = tssbo;
}
else {
tssbo2 = tssbo2 - 5;
if (tssbo2 < 0 && tmmbo2 == 0) {
tssbo2 = 0, tmmbo2 = 0;
}
if (tssbo2 < 0) {
tssbo2 = 55;
tmmbo2 = tmmbo2 - 1;
}
bo2 = 0;
mmbo2 = tmmbo2;
ssbo2 = tssbo2;
}
if (bopage == 0) {
display.setCursor (60, 15);
display.print((mmbo / 10) % 10);
display.print(mmbo % 10);
display.print(":");
display.print((ssbo / 10) % 10);
display.print(ssbo % 10);
}
else {
display.setCursor (60, 30);
display.print((mmbo2 / 10) % 10);
display.print(mmbo2 % 10);
display.print(":");
display.print((ssbo2 / 10) % 10);
display.print(ssbo2 % 10);
}
delay(200);
}
display.setCursor(0, 0);
display.print("Run:");
if (bopage == 0) {
display.setCursor (0, 15);
display.print("BO 1: <-");
display.setCursor (0, 30);
display.print("BO 2:");
}
else {
display.setCursor (0, 15);
display.print("BO 1: ");
display.setCursor (0, 30);
display.print("BO 2: <");
}
//Runtime timer
display.setCursor (30, 0);
display.print((hh / 10) % 10);
display.print(hh % 10);
display.print(":");
display.print((mm / 10) % 10);
display.print(mm % 10);
display.print(":");
display.print((ss / 10) % 10);
display.print(ss % 10);
//if (bopage == 0){
display.setCursor (40, 15);
display.print((mmbo / 10) % 10);
display.print(mmbo % 10);
display.print(":");
display.print((ssbo / 10) % 10);
display.print(ssbo % 10);
//}
//else {
display.setCursor (40, 30);
display.print((mmbo2 / 10) % 10);
display.print(mmbo2 % 10);
display.print(":");
display.print((ssbo2 / 10) % 10);
display.print(ssbo2 % 10);
//}
}
ISR(TIMER1_COMPA_vect) {
if (run == true) {
ms = ms + 1;
if (ms > 999) {
ms = 0;
ss = ss + 1;
}
if (ss > 59) {
ss = 0;
mm = mm + 1;
}
if (mm > 59) {
mm = 0;
hh = hh + 1;
}
}
if (bopage == 0) {
if (hhbo == 0 && mmbo == 0 && ssbo == 0 && msbo == 0) {
bo = 0;
}
if (bo == 1) {
msbo = msbo - 1;
if (msbo < 0) {
msbo = 999; ssbo = ssbo - 1;
if (ssbo < 0) {
ssbo = 59;
mmbo = mmbo - 1;
}
if (mmbo < 0) {
mmbo = 59;
hhbo = hhbo - 1;
}
if (hhbo < 0) {
hhbo = 0;
}
}
//EVERYTHING WORKS UNTIL THIS POINT, DOWN FROM HERE NOT DOING THE COUNTS
if (bopage == 1) {
if (hhbo2 == 0 && mmbo2 == 0 && ssbo2 == 0 && msbo2 == 0) {
bo2 = 0;
}
if (bo2 == 1) {
msbo2 = msbo2 - 1;
if (msbo2 < 0) {
msbo2 = 999; ssbo2 = ssbo2 - 1;
if (ssbo2 < 0) {
ssbo2 = 59;
mmbo2 = mmbo2 - 1;
}
if (mmbo2 < 0) {
mmbo2 = 59;
hhbo2 = hhbo2 - 1;
}
if (hhbo2 < 0) {
hhbo2 = 0;
}
}
}
}
}
}
}
If instead you put all the clock tick code (now in the ISR) in a separate function called by the main loop, you can debug it using Serial.print() statements.
do you mean like: void function and void function 2?
Something like this.
In loop() put
if (tick) {
tick_update();
tick=0; //reset tick flag
}
And for the rest (possible nested if errors not fixed)
volatile byte tick = 0; //global flag variable
ISR(TIMER1_COMPA_vect) {
tick = 1; //set flag
}
void tick_update() {
if (run == true) {
ms = ms + 1;
if (ms > 999) {
ms = 0;
ss = ss + 1;
}
if (ss > 59) {
ss = 0;
mm = mm + 1;
}
if (mm > 59) {
mm = 0;
hh = hh + 1;
}
}
if (bopage == 0) {
if (hhbo == 0 && mmbo == 0 && ssbo == 0 && msbo == 0) {
bo = 0;
}
if (bo == 1) {
msbo = msbo - 1;
if (msbo < 0) {
msbo = 999; ssbo = ssbo - 1;
if (ssbo < 0) {
ssbo = 59;
mmbo = mmbo - 1;
}
if (mmbo < 0) {
mmbo = 59;
hhbo = hhbo - 1;
}
if (hhbo < 0) {
hhbo = 0;
}
}
//EVERYTHING WORKS UNTIL THIS POINT, DOWN FROM HERE NOT DOING THE COUNTS
if (bopage == 1) {
if (hhbo2 == 0 && mmbo2 == 0 && ssbo2 == 0 && msbo2 == 0) {
bo2 = 0;
}
if (bo2 == 1) {
msbo2 = msbo2 - 1;
if (msbo2 < 0) {
msbo2 = 999; ssbo2 = ssbo2 - 1;
if (ssbo2 < 0) {
ssbo2 = 59;
mmbo2 = mmbo2 - 1;
}
if (mmbo2 < 0) {
mmbo2 = 59;
hhbo2 = hhbo2 - 1;
}
if (hhbo2 < 0) {
hhbo2 = 0;
}
}
}
}
}
}
}
Did you review your code after @jremington republished it? You should use Ctrl-T while editing to reformat the code and review it often.
You will realize it is not a problem of the ISR, but of your logic.
Hint: look at nested if's
And your ISR could be shorted to one instruction, handle the rest in the main program. Make sure to understand what volatile means and ...use it.
#include <SPI.h> // include SPI library
#include <Adafruit_GFX.h> // include adafruit graphics library
#include <Adafruit_PCD8544.h> // include adafruit PCD8544 (Nokia 5110) library
#define bt_1 8
#define bt_2 9
#define bt_3 10
#define bt_4 11
#define bt_5 12
#define bt_6 1
int bopage = 0;
int bo = 0;
int bo2 = 0;
int hh = 0, mm = 0, ss = 0, ms = 0;
int hhbo = 0, mmbo = 9, ssbo = 30, msbo = 0;
int tmmbo = 9, tssbo = 30, tmsbo = 0;
int hhbo2 = 0, mmbo2 = 8, ssbo2 = 35, msbo2 = 0;
int tmmbo2 = 8, tssbo2 = 35, tmsbo2 = 0;
bool run = true;
// Nokia 5110 LCD module connections (CLK, DIN, D/C, CS, RST)
Adafruit_PCD8544 display = Adafruit_PCD8544(6, 5, 4, 3, 2);
void setup() {
// put your setup code here, to run once:
display.begin();
display.setContrast(45);
display.clearDisplay(); // clear the screen and buffer
display.display();
display.setTextSize(1, 2);
display.setTextColor(BLACK, WHITE);
display.display();
pinMode(bt_1, INPUT_PULLUP);
pinMode(bt_2, INPUT_PULLUP);
pinMode(bt_3, INPUT_PULLUP);
pinMode(bt_4, INPUT_PULLUP);
pinMode(bt_5, INPUT_PULLUP);
pinMode(bt_6, INPUT_PULLUP);
noInterrupts(); // disable all interrupts
TCCR1A = 0; // set entire TCCR1A register to 0 //set timer1 interrupt at 1kHz // 1 ms
TCCR1B = 0; // same for TCCR1B
TCNT1 = 0; // set timer count for 1khz increments
OCR1A = 1999; // = (16*10^6) / (1000*8) - 1
//had to use 16 bit timer1 for this bc 1999>255, but could switch to timers 0 or 2 with larger prescaler
// turn on CTC mode
TCCR1B |= (1 << WGM12); // Set CS11 bit for 8 prescaler
TCCR1B |= (1 << CS11); // enable timer compare interrupt
TIMSK1 |= (1 << OCIE1A);
interrupts(); // enable
}
void loop() {
// put your main code here, to run repeatedly:
display.display();
if (digitalRead(bt_1) == 0 && run == true) { //Pause stopwatch
run = false;
delay(200);
}
if (digitalRead(bt_1) == 0 && run == false) { //Start stopwatch
run = true;
delay(200);
}
if (digitalRead(bt_6) == 0) {
ms = 0, ss = 0, mm = 0, hh = 0; // Reset stopwatch
run = false;
delay(100);
}
if (digitalRead(bt_3) == 0) {
if (bopage == 0) {
msbo = 0, ssbo = tssbo, mmbo = tmmbo, hhbo = 0, bo = 1; // Reset stopwatch
}
if (bopage == 1) {
msbo2 = 0, ssbo2 = tssbo2, mmbo2 = tmmbo2, hhbo2 = 0, bo2 = 1; // Reset stopwatch
}
delay(100);
}
if (digitalRead(bt_2) == 0) {
if (bopage == 0) {
bopage = 1;
} else {
bopage = 0;
}
delay(100);
}
if (digitalRead(bt_4) == 0) { //+ 5s bo
if (bopage == 0) {
tssbo = tssbo + 5;
if (tssbo >= 60) {
tssbo = 0;
tmmbo = tmmbo + 1;
}
bo = 0;
mmbo = tmmbo;
ssbo = tssbo;
}
if (bopage == 1) {
tssbo2 = tssbo2 + 5;
if (tssbo2 >= 60) {
tssbo2 = 0;
tmmbo2 = tmmbo2 + 1;
}
bo2 = 0;
mmbo2 = tmmbo2;
ssbo2 = tssbo2;
}
delay(100);
}
if (digitalRead(bt_5) == 0) { //- 5s bo
if (bopage == 0) {
tssbo = tssbo - 5;
if (tssbo < 0 && tmmbo == 0) { tssbo = 0, tmmbo = 0; }
if (tssbo < 0) {
tssbo = 55;
tmmbo = tmmbo - 1;
}
bo = 0;
mmbo = tmmbo;
ssbo = tssbo;
}
if (bopage == 1) {
tssbo2 = tssbo2 - 5;
if (tssbo2 < 0 && tmmbo2 == 0) { tssbo2 = 0, tmmbo2 = 0; }
if (tssbo2 < 0) {
tssbo2 = 55;
tmmbo2 = tmmbo2 - 1;
}
bo2 = 0;
mmbo2 = tmmbo2;
ssbo2 = tssbo2;
}
delay(100);
}
display.setCursor(0, 0);
display.print("Run:");
if (bopage == 0) {
display.setCursor(0, 15);
display.print("BO 1: <-");
display.setCursor(0, 30);
display.print("BO 2: ");
} else {
display.setCursor(0, 15);
display.print("BO 1: ");
display.setCursor(0, 30);
display.print("BO 2: <-");
}
//Runtime timer
display.setCursor(30, 0);
display.print((hh / 10) % 10);
display.print(hh % 10);
display.print(":");
display.print((mm / 10) % 10);
display.print(mm % 10);
display.print(":");
display.print((ss / 10) % 10);
display.print(ss % 10);
display.setCursor(40, 15);
display.print((mmbo / 10) % 10);
display.print(mmbo % 10);
display.print(":");
display.print((ssbo / 10) % 10);
display.print(ssbo % 10);
display.setCursor(40, 30);
display.print((mmbo2 / 10) % 10);
display.print(mmbo2 % 10);
display.print(":");
display.print((ssbo2 / 10) % 10);
display.print(ssbo2 % 10);
}
void bocount() {
if (hhbo == 0 && mmbo == 0 && ssbo == 0 && msbo == 0) {
bo = 0;
}
if (bo == 1) {
msbo = msbo - 1;
if (msbo < 0) {
msbo = 999;
ssbo = ssbo - 1;
if (ssbo < 0) {
ssbo = 59;
mmbo = mmbo - 1;
}
if (mmbo < 0) {
mmbo = 59;
hhbo = hhbo - 1;
}
if (hhbo < 0) { hhbo = 0; }
}
}
if (hhbo2 == 0 && mmbo2 == 0 && ssbo2 == 0 && msbo2 == 0) {
bo2 = 0;
}
if (bo2 == 1) {
msbo2 = msbo2 - 1;
if (msbo2 < 0) {
msbo2 = 999;
ssbo2 = ssbo2 - 1;
if (ssbo2 < 0) {
ssbo2 = 59;
mmbo2 = mmbo2 - 1;
}
if (mmbo2 < 0) {
mmbo2 = 59;
hhbo2 = hhbo2 - 1;
}
if (hhbo2 < 0) { hhbo2 = 0; }
}
}
}
ISR(TIMER1_COMPA_vect) {
if (run == true) {
ms = ms + 1;
if (ms > 999) {
ms = 0;
ss = ss + 1;
}
if (ss > 59) {
ss = 0;
mm = mm + 1;
}
if (mm > 59) {
mm = 0;
hh = hh + 1;
}
}
bocount();
}
Got all working as it should, had some other promblems too but they are also solved. Thanks for help!
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.