https://rudysarduinoprojects.wordpress.com/2019/02/10/fun-with-arduino-13-timer-with-millis-no-delay-multitasking/
#define INTERVAL_1 200 // [ms] #define INTERVAL_2 1100 // [ms] byte led_1; byte led_2; unsigned long time_for_action_1; unsigned long time_for_action_2; void setup() { pinMode(8, OUTPUT); pinMode(9, OUTPUT); } void loop() { if (millis() > time_for_action_1) { time_for_action_1 = millis() + (unsigned long)INTERVAL_1; led_1 = !led_1; digitalWrite(8, led_1); } if (millis() > time_for_action_2) { time_for_action_2 = millis() + (unsigned long)INTERVAL_2; led_2 = !led_2; digitalWrite(9, led_2); } }
No comments:
Post a Comment