Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <TimerOne.h>
- #define LED_PIN 4
- unsigned long int interval = 0-1; // just to get biggest possible value
- unsigned long int current_time = 0;
- unsigned long int start_time = 0;
- bool state = false;
- bool previous_state = !state; // it need to different
- void change_led_state(){
- state = !state;
- digitalWrite(LED_PIN, state);
- }
- void setup(){
- pinMode(LED_PIN, OUTPUT);
- Serial.begin(9600);
- }
- void loop(){
- if(state != previous_state){ // if Timer1 was executed
- previous_state = state;
- current_time = millis();
- Serial.print("Interval was: ");
- Serial.println(current_time - start_time);
- Timer1.initialize(interval);
- Timer1.attachInterrupt(change_led_state);
- start_time = current_time;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement