BlockNot icon indicating copy to clipboard operation
BlockNot copied to clipboard

Problems with start/stop/reset timer

Open mrHubdoc opened this issue 2 years ago • 2 comments

I do like this like that. Does not start the timer.

if (DOOR_CLOSE == 1) { TVATTSTEP = 1; TvattTimer.START_RESET; }

If I do this the timer start. What am I doing wrong? if (flagga == 1) { TvattTimer.START_RESET; flagga = 0; switch (TVATTSTEP) { case 0: //do something when var equals 0 SP_set(); digitalWrite(PUMP, LOW); digitalWrite(HEAT, LOW); if (DOOR_CLOSE == 1) { TVATTSTEP = 1; flagga = 1; } break;

mrHubdoc avatar Nov 30 '23 07:11 mrHubdoc

I use ATmega338P Old Bootloader. Arduino NANO

mrHubdoc avatar Nov 30 '23 08:11 mrHubdoc

@mrHubdoc

First of all, when using this format for communicating, leverage the tools provided in the editor.

You should present code, formatted in proper markdown code blocks by pasting your code, then either highlighting it and pressing the code button <> at the top, or using the three back-tick marks so that it looks like this:

if (DOOR_CLOSE == 1) { 
     TVATTSTEP = 1;
     TvattTimer.START_RESET; 
}

The next code segment that you sent, you sent it all as one line with no formatting at all. What that looks like from my perspective, is that you can't be bothered to take the time to format your code so that it is readable but you think it's fine to waste my time formatting your code so that I can read it ... that kind of careless posting won't get you very far with people.

if (flagga == 1) {
    TvattTimer.START_RESET;
    flagga = 0;

    switch (TVATTSTEP) {

        case 0:
            // do something when var equals 0
            SP_set();
            digitalWrite(PUMP, LOW);
            digitalWrite(HEAT, LOW);

            if (DOOR_CLOSE == 1) {
                TVATTSTEP = 1;
                flagga = 1;
            }
            break;
        //... other cases (if any) go here
    }
}

Now, let's talk about the code ... in your first if statement, you say the timer doesn't start, but in the second if statement it does start.

Based on the information you've given me, I can only assume that in the first scenario, your if condition never tests as being true but in the second if condition that you posted, it does test true. So when you're running the code, DOOR_CLOSE does not actually equal 1 while flagga does ... and this is why the timer starts for the second if clause and not the first.

Without more information, I have no other explanation beyond looking at the code you provided.

EasyG0ing1 avatar Jan 07 '24 08:01 EasyG0ing1