Advertisement
The_red_Freak

Untitled

Nov 18th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None | 0 0
  1. void setup() {
  2.   pinMode(2, OUTPUT);
  3.   Serial.begin(115200);
  4. }
  5.  
  6. void Task_1ms() {
  7.  
  8. }
  9.  
  10. static boolean toggle;
  11.  
  12. void Task_500ms() {
  13.   digitalWrite(2, toggle);
  14.  
  15.  
  16.   Serial.write("\nPin Status: " + toggle);
  17.  
  18.   if (toggle) toggle = false; else toggle = true;
  19.  
  20. }
  21.  
  22.  
  23. void loop() {
  24.  
  25.   Serial.write("Loop Heartbeat\n");
  26.  
  27.   uint64_t t_us = micros();
  28.   static uint64_t mt_us = 0;
  29.   static uint64_t mt_5us = 0;
  30.  
  31.   if (t_us >= (mt_us + 1000uL))
  32.   {
  33.     Task_1ms();
  34.     mt_us = t_us;
  35.   }
  36.  
  37.   if (t_us >= (mt_5us + (500 * 1000uL)))
  38.   {
  39.    
  40.   Serial.write("500ms\n");
  41.     Task_500ms();
  42.     mt_5us = t_us;
  43.   }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement