Advertisement
pleasedontcode

millis example

Sep 15th, 2024
354
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Arduino 0.45 KB | Source Code | 0 0
  1. unsigned long previousMillis1 = 0;
  2. unsigned long previousMillis2 = 0;
  3. const long interval1 = 1000;
  4. const long interval2 = 500;
  5.  
  6. void loop() {
  7.     unsigned long currentMillis = millis();
  8.  
  9.     if (currentMillis - previousMillis1 >= interval1) {
  10.         previousMillis1 = currentMillis;
  11.         // Task 1 code
  12.     }
  13.  
  14.     if (currentMillis - previousMillis2 >= interval2) {
  15.         previousMillis2 = currentMillis;
  16.         // Task 2 code
  17.     }
  18. }
  19.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement