TeensyNanoExoCode
Loading...
Searching...
No Matches
SyncLed.h
Go to the documentation of this file.
1
31#ifndef SyncLed_h
32#define SyncLed_h
33// Arduino compiles everything in the src folder even if not included so it causes and error for the nano if this is not included.
34#if defined(ARDUINO_TEENSY36) || defined(ARDUINO_TEENSY41)
35#include "Arduino.h"
36#include "Board.h"
37#include "config.h"
38//#include "IntervalTimer.h"
39
40// Define the on and off state of the LED. This is handy for if you are using a P Channel MOSFET where low is on.
41//#define SYNC_LED_ON_STATE HIGH
42//#define SYNC_LED_OFF_STATE LOW
43
44// const unsigned int SYNC_HALF_PERIOD_US = 125000; // half blink period in micro seconds
45// const unsigned int SYNC_START_STOP_HALF_PERIOD_US = 4 * SYNC_HALF_PERIOD_US; // Half blink period for the begining and end of the sequence. This is usually longer so it is easy to identify.
46
47
52class SyncLed
53{
54 public:
55 // Constructors one you can set the default LED State
56 SyncLed(int pin, int sync_start_stop_half_period_us, int sync_half_period_us);
57 SyncLed(int pin, int sync_start_stop_half_period_us, int sync_half_period_us, int default_led_state);
58 SyncLed(int pin, int sync_start_stop_half_period_us, int sync_half_period_us, int default_led_state, int led_default_state_pin); // This isn't a great way of overloading but with high and low being int instead of bool I don't have a great alternative
59
63 void trigger();
64
69 void update_led(); // Changes the LED State to the current state
70
77 void update_periods(int sync_start_stop_half_period_us, int sync_half_period_us); // Used if you need to change the periods after initialization
78
84 bool handler();
85
91 void set_default_state(int new_default);
92
98 bool get_led_is_on(); //
99
105 bool get_is_blinking();
106
107
108
109 private:
110
111
115 void _blink_start_stop();
116
120 void _blink();
121
125 void _default_state();
126
127 volatile int _led_state;
128 int _led_is_on;
129 volatile int _current_sync_period;
130 volatile bool _do_blink ;
131 volatile bool _do_start_stop_sequence;
132 bool _is_blinking;
134 int _pin;
135 int _default_led_state;
136 int _led_default_state_pin;
138 int _sync_start_stop_half_period_us;
139 int _sync_half_period_us;
140 volatile unsigned int _state_change_count ;
141 unsigned int _num_start_stop_blinks;
142 int _last_state_change_timestamp_us;
144};
145#endif
146#endif