Advertisement
tburton

Untitled

May 24th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.76 KB | None | 0 0
  1. #include <TimerOne.h>
  2.  
  3. #define LED_PIN 4
  4.  
  5. unsigned long int interval = 0-1;  // just to get biggest possible value
  6. unsigned long int current_time = 0;
  7. unsigned long int start_time = 0;
  8.  
  9. bool state = false;
  10. bool previous_state = !state; // it need to different
  11.  
  12. void change_led_state(){
  13.   state = !state;
  14.   digitalWrite(LED_PIN, state);
  15. }
  16.  
  17. void setup(){
  18.   pinMode(LED_PIN, OUTPUT);
  19.   Serial.begin(9600);
  20. }
  21.  
  22. void loop(){
  23.     if(state != previous_state){  // if Timer1 was executed
  24.       previous_state = state;
  25.       current_time = millis();
  26.       Serial.print("Interval was: ");
  27.       Serial.println(current_time - start_time);
  28.       Timer1.initialize(interval);
  29.       Timer1.attachInterrupt(change_led_state);
  30.       start_time = current_time;
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement