jurevycius3 Postat Noiembrie 10, 2018 Partajează Postat Noiembrie 10, 2018 Hello, I want to help me with a problem, I have the code but not work in a correct mode (code is below). If I press the button ZS_1 and after 1 second I press the another button RB4_bit Relay_back doesn't work because the timer is too long in cycle. Please help me with another expression. Best regards ! do{ if ((SZ_1 == 1) || (RB1_bit == 1) || (RB2_bit == 1) || (RB3_bit == 1)) { Delay_ms(80); Relay_front=1; Delay_ms(10000); Relay_front=0; } else if ((RB4_bit == 1) || (RB5_bit == 1)) { Delay_ms(80); Relay_back=1; Delay_ms(10000); Relay_back=0; } } while(1); } Link spre comentariu
Vizitator Postat Noiembrie 10, 2018 Partajează Postat Noiembrie 10, 2018 (editat) Maybe "Delay_ms(80)" must be biger than 10000. Try do{ if ((SZ_1 == 1) || (RB1_bit == 1) || (RB2_bit == 1) || (RB3_bit == 1)) { Delay_ms(200000); Relay_front=1; Delay_ms(10000); Relay_front=0; } else if ((RB4_bit == 1) || (RB5_bit == 1)) { Delay_ms(200000); Relay_back=1; Delay_ms(10000); Relay_back=0; } } while(1); } Editat Noiembrie 10, 2018 de Vizitator Link spre comentariu
Mircea Postat Noiembrie 10, 2018 Partajează Postat Noiembrie 10, 2018 Fanele, what's the point of having 200 seconds delays? Delay_ms(200000) = 200 seconds. @jurevycius3, please post complete code (use the <> button to add code format) and the used schematic. Link spre comentariu
Mircea Postat Noiembrie 10, 2018 Partajează Postat Noiembrie 10, 2018 (editat) In your code, you have to wait at least 10 seconds before you can do something on RB4 or RB5. And the same 10 seconds until you can do something on SZ_, RB1... 3. Editat Noiembrie 10, 2018 de Thunderer Link spre comentariu
jurevycius3 Postat Noiembrie 10, 2018 Autor Partajează Postat Noiembrie 10, 2018 4 minutes ago, Thunderer2018 said: In your code, you have to wait at least 10 seconds before you can do something on RB4 or RB5. ten seconds Link spre comentariu
Vizitator Postat Noiembrie 10, 2018 Partajează Postat Noiembrie 10, 2018 So, after a short search on google, I think this is the logic diagram of what you need. You must change the green fields. 1000 ms=1sec. Link spre comentariu
jurevycius3 Postat Noiembrie 10, 2018 Autor Partajează Postat Noiembrie 10, 2018 44 minutes ago, Fan Elforum said: So, after a short search on google, I think this is the logic diagram of what you need. You must change the green fields. 1000 ms=1sec. ok....thanks ! Link spre comentariu
bcristian Postat Noiembrie 10, 2018 Partajează Postat Noiembrie 10, 2018 https://randomnerdtutorials.com/why-you-shouldnt-always-use-the-arduino-delay-function/ Do not use delay() if your program handles user input, because delay() blocks the system (as far as your program logic is concerned), i.e. nothing happens during that time, not even checking that the user pressed some button. What you should do instead is use state machine logic, i.e. something like: int state = 0; ulong stateStart, stateDuration; while (1) { ulong crtTime = millis(); switch (state) { case 0: // relay off, button not pressed if (button_pressed) { state = 1; stateStart = crtTime; stateDuration = 80; } break; case 1: // delay between button press and activating relay if (crtTime - stateDuration >= stateStart) // testing this way avoids the overflow error { state = 2; stateStart = crtTime; stateDuration = 10000; relayState = 1; // relay on } break; case 2: // relay on time if (crtTime - stateDuration >= stateStart) { state = 0; relayState = 0; // relay off } break; } } Link spre comentariu
jurevycius3 Postat Noiembrie 11, 2018 Autor Partajează Postat Noiembrie 11, 2018 14 hours ago, bcristian said: https://randomnerdtutorials.com/why-you-shouldnt-always-use-the-arduino-delay-function/ Do not use delay() if your program handles user input, because delay() blocks the system (as far as your program logic is concerned), i.e. nothing happens during that time, not even checking that the user pressed some button. What you should do instead is use state machine logic, i.e. something like: int state = 0; ulong stateStart, stateDuration; while (1) { ulong crtTime = millis(); switch (state) { case 0: // relay off, button not pressed if (button_pressed) { state = 1; stateStart = crtTime; stateDuration = 80; } break; case 1: // delay between button press and activating relay if (crtTime - stateDuration >= stateStart) // testing this way avoids the overflow error { state = 2; stateStart = crtTime; stateDuration = 10000; relayState = 1; // relay on } break; case 2: // relay on time if (crtTime - stateDuration >= stateStart) { state = 0; relayState = 0; // relay off } break; } } I understood, thank you very much ! Link spre comentariu
Postări Recomandate
Creează un cont sau autentifică-te pentru a adăuga comentariu
Trebuie să fi un membru pentru a putea lăsa un comentariu.
Creează un cont
Înregistrează-te pentru un nou cont în comunitatea nostră. Este simplu!
Înregistrează un nou contAutentificare
Ai deja un cont? Autentifică-te aici.
Autentifică-te acum