Rollback to v2.0.0beta3 - reverting changes from v2.0.0
This commit is contained in:
@ -2,8 +2,8 @@
|
||||
* @file analog_input.h
|
||||
* @author Adam Wonak (https://github.com/awonak)
|
||||
* @brief Class for interacting with analog inputs.
|
||||
* @version 2.0.0
|
||||
* @date 2025-08-17
|
||||
* @version 0.1
|
||||
* @date 2025-05-23
|
||||
*
|
||||
* @copyright MIT - (c) 2025 - Adam Wonak - adam.wonak@gmail.com
|
||||
*
|
||||
@ -11,92 +11,94 @@
|
||||
#ifndef ANALOG_INPUT_H
|
||||
#define ANALOG_INPUT_H
|
||||
|
||||
const int MAX_INPUT = (1 << 10) - 1; // Max 10 bit analog read resolution.
|
||||
const int MAX_INPUT = (1 << 10) - 1; // Max 10 bit analog read resolution.
|
||||
|
||||
// estimated default calibration value
|
||||
const int CALIBRATED_LOW = -566;
|
||||
const int CALIBRATED_HIGH = 512;
|
||||
|
||||
class AnalogInput {
|
||||
public:
|
||||
static const int GATE_THRESHOLD = 0;
|
||||
public:
|
||||
static const int GATE_THRESHOLD = 0;
|
||||
|
||||
AnalogInput() {}
|
||||
~AnalogInput() {}
|
||||
AnalogInput() {}
|
||||
~AnalogInput() {}
|
||||
|
||||
/**
|
||||
* Initializes a analog input object.
|
||||
*
|
||||
* @param pin gpio pin for the analog input.
|
||||
*/
|
||||
void Init(uint8_t pin) {
|
||||
pinMode(pin, INPUT);
|
||||
pin_ = pin;
|
||||
}
|
||||
/**
|
||||
* Initializes a analog input object.
|
||||
*
|
||||
* @param pin gpio pin for the analog input.
|
||||
*/
|
||||
void Init(uint8_t pin) {
|
||||
pinMode(pin, INPUT);
|
||||
pin_ = pin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the value of the analog input and set instance state.
|
||||
*
|
||||
*/
|
||||
void Process() {
|
||||
old_read_ = read_;
|
||||
int raw = analogRead(pin_);
|
||||
read_ = map(raw, 0, MAX_INPUT, low_, high_);
|
||||
read_ = constrain(read_ - offset_, -512, 512);
|
||||
if (inverted_) read_ = -read_;
|
||||
}
|
||||
/**
|
||||
* Read the value of the analog input and set instance state.
|
||||
*
|
||||
*/
|
||||
void Process() {
|
||||
old_read_ = read_;
|
||||
int raw = analogRead(pin_);
|
||||
read_ = map(raw, 0, MAX_INPUT, low_, high_);
|
||||
read_ = constrain(read_ - offset_, -512, 512);
|
||||
if (inverted_)
|
||||
read_ = -read_;
|
||||
}
|
||||
|
||||
// Set calibration values.
|
||||
// Set calibration values.
|
||||
|
||||
void AdjustCalibrationLow(int amount) { low_ += amount; }
|
||||
void AdjustCalibrationLow(int amount) { low_ += amount; }
|
||||
|
||||
void AdjustCalibrationHigh(int amount) { high_ += amount; }
|
||||
void AdjustCalibrationHigh(int amount) { high_ += amount; }
|
||||
|
||||
void SetOffset(float percent) { offset_ = -(percent)*512; }
|
||||
void SetOffset(float percent) { offset_ = -(percent) * 512; }
|
||||
|
||||
void SetAttenuation(float percent) {
|
||||
low_ = abs(percent) * CALIBRATED_LOW;
|
||||
high_ = abs(percent) * CALIBRATED_HIGH;
|
||||
inverted_ = percent < 0;
|
||||
}
|
||||
void SetAttenuation(float percent) {
|
||||
low_ = abs(percent) * CALIBRATED_LOW;
|
||||
high_ = abs(percent) * CALIBRATED_HIGH;
|
||||
inverted_ = percent < 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current value of the analog input within a range of +/-512.
|
||||
*
|
||||
* @return read value within a range of +/-512.
|
||||
*
|
||||
*/
|
||||
inline int16_t Read() { return read_; }
|
||||
/**
|
||||
* Get the current value of the analog input within a range of +/-512.
|
||||
*
|
||||
* @return read value within a range of +/-512.
|
||||
*
|
||||
*/
|
||||
inline int16_t Read() { return read_; }
|
||||
|
||||
/**
|
||||
* Return the analog read value as voltage.
|
||||
*
|
||||
* @return A float representing the voltage (-5.0 to +5.0).
|
||||
*
|
||||
*/
|
||||
inline float Voltage() { return ((read_ / 512.0) * 5.0); }
|
||||
/**
|
||||
* Return the analog read value as voltage.
|
||||
*
|
||||
* @return A float representing the voltage (-5.0 to +5.0).
|
||||
*
|
||||
*/
|
||||
inline float Voltage() { return ((read_ / 512.0) * 5.0); }
|
||||
|
||||
/**
|
||||
* Checks for a rising edge transition across a threshold.
|
||||
*
|
||||
* @param threshold The value that the input must cross.
|
||||
* @return True if the value just crossed the threshold from below, false otherwise.
|
||||
*/
|
||||
inline bool IsRisingEdge(int16_t threshold) const {
|
||||
bool was_high = old_read_ > threshold;
|
||||
bool is_high = read_ > threshold;
|
||||
return is_high && !was_high;
|
||||
}
|
||||
/**
|
||||
* Checks for a rising edge transition across a threshold.
|
||||
*
|
||||
* @param threshold The value that the input must cross.
|
||||
* @return True if the value just crossed the threshold from below, false
|
||||
* otherwise.
|
||||
*/
|
||||
inline bool IsRisingEdge(int16_t threshold) const {
|
||||
bool was_high = old_read_ > threshold;
|
||||
bool is_high = read_ > threshold;
|
||||
return is_high && !was_high;
|
||||
}
|
||||
|
||||
private:
|
||||
uint8_t pin_;
|
||||
int16_t read_;
|
||||
uint16_t old_read_;
|
||||
// calibration values.
|
||||
int offset_ = 0;
|
||||
int low_ = CALIBRATED_LOW;
|
||||
int high_ = CALIBRATED_HIGH;
|
||||
bool inverted_ = false;
|
||||
private:
|
||||
uint8_t pin_;
|
||||
int16_t read_;
|
||||
uint16_t old_read_;
|
||||
// calibration values.
|
||||
int offset_ = 0;
|
||||
int low_ = CALIBRATED_LOW;
|
||||
int high_ = CALIBRATED_HIGH;
|
||||
bool inverted_ = false;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@ -2,8 +2,8 @@
|
||||
* @file button.h
|
||||
* @author Adam Wonak (https://github.com/awonak)
|
||||
* @brief Wrapper class for interacting with trigger / gate inputs.
|
||||
* @version 2.0.0
|
||||
* @date 2025-08-17
|
||||
* @version 0.1
|
||||
* @date 2025-04-20
|
||||
*
|
||||
* @copyright MIT - (c) 2025 - Adam Wonak - adam.wonak@gmail.com
|
||||
*
|
||||
|
||||
296
src/clock.h
296
src/clock.h
@ -2,9 +2,9 @@
|
||||
* @file clock.h
|
||||
* @author Adam Wonak (https://github.com/awonak)
|
||||
* @brief Wrapper Class for clock timing functions.
|
||||
* @version 2.0.0
|
||||
* @date 2025-08-17
|
||||
*
|
||||
* @version 0.1
|
||||
* @date 2025-05-04
|
||||
*
|
||||
* @copyright MIT - (c) 2025 - Adam Wonak - adam.wonak@gmail.com
|
||||
*
|
||||
*/
|
||||
@ -17,7 +17,8 @@
|
||||
#include "peripherials.h"
|
||||
#include "uClock/uClock.h"
|
||||
|
||||
// MIDI clock, start, stop, and continue byte definitions - based on MIDI 1.0 Standards.
|
||||
// MIDI clock, start, stop, and continue byte definitions - based on MIDI 1.0
|
||||
// Standards.
|
||||
#define MIDI_CLOCK 0xF8
|
||||
#define MIDI_START 0xFA
|
||||
#define MIDI_STOP 0xFC
|
||||
@ -28,169 +29,158 @@ static ExtCallback extUserCallback = nullptr;
|
||||
static void serialEventNoop(uint8_t msg, uint8_t status) {}
|
||||
|
||||
class Clock {
|
||||
public:
|
||||
static constexpr int DEFAULT_TEMPO = 120;
|
||||
public:
|
||||
static constexpr int DEFAULT_TEMPO = 120;
|
||||
|
||||
enum Source {
|
||||
SOURCE_INTERNAL,
|
||||
SOURCE_EXTERNAL_PPQN_24,
|
||||
SOURCE_EXTERNAL_PPQN_4,
|
||||
SOURCE_EXTERNAL_PPQN_1,
|
||||
SOURCE_EXTERNAL_MIDI,
|
||||
SOURCE_LAST,
|
||||
};
|
||||
enum Source {
|
||||
SOURCE_INTERNAL,
|
||||
SOURCE_EXTERNAL_PPQN_24,
|
||||
SOURCE_EXTERNAL_PPQN_4,
|
||||
SOURCE_EXTERNAL_PPQN_2,
|
||||
SOURCE_EXTERNAL_PPQN_1,
|
||||
SOURCE_EXTERNAL_MIDI,
|
||||
SOURCE_LAST,
|
||||
};
|
||||
|
||||
enum Pulse {
|
||||
PULSE_NONE,
|
||||
PULSE_PPQN_24,
|
||||
PULSE_PPQN_4,
|
||||
PULSE_PPQN_1,
|
||||
PULSE_LAST,
|
||||
};
|
||||
enum Pulse {
|
||||
PULSE_NONE,
|
||||
PULSE_PPQN_1,
|
||||
PULSE_PPQN_4,
|
||||
PULSE_PPQN_24,
|
||||
PULSE_LAST,
|
||||
};
|
||||
|
||||
void Init() {
|
||||
NeoSerial.begin(31250);
|
||||
void Init() {
|
||||
NeoSerial.begin(31250);
|
||||
|
||||
// Initialize the clock library
|
||||
uClock.init();
|
||||
uClock.setClockMode(uClock.INTERNAL_CLOCK);
|
||||
uClock.setOutputPPQN(uClock.PPQN_96);
|
||||
uClock.setTempo(DEFAULT_TEMPO);
|
||||
// Initialize the clock library
|
||||
uClock.init();
|
||||
uClock.setClockMode(uClock.INTERNAL_CLOCK);
|
||||
uClock.setOutputPPQN(uClock.PPQN_96);
|
||||
uClock.setTempo(DEFAULT_TEMPO);
|
||||
|
||||
// MIDI events.
|
||||
uClock.setOnClockStart(sendMIDIStart);
|
||||
uClock.setOnClockStop(sendMIDIStop);
|
||||
uClock.setOnSync24(sendMIDIClock);
|
||||
// MIDI events.
|
||||
uClock.setOnClockStart(sendMIDIStart);
|
||||
uClock.setOnClockStop(sendMIDIStop);
|
||||
uClock.setOnSync24(sendMIDIClock);
|
||||
|
||||
uClock.start();
|
||||
uClock.start();
|
||||
}
|
||||
|
||||
// Handle external clock tick and call user callback when receiving clock
|
||||
// trigger (PPQN_4, PPQN_24, or MIDI).
|
||||
void AttachExtHandler(void (*callback)()) {
|
||||
extUserCallback = callback;
|
||||
attachInterrupt(digitalPinToInterrupt(EXT_PIN), callback, RISING);
|
||||
}
|
||||
|
||||
// Internal PPQN96 callback for all clock timer operations.
|
||||
void AttachIntHandler(void (*callback)(uint32_t)) {
|
||||
uClock.setOnOutputPPQN(callback);
|
||||
}
|
||||
|
||||
// Set the source of the clock mode.
|
||||
void SetSource(Source source) {
|
||||
bool was_playing = !IsPaused();
|
||||
uClock.stop();
|
||||
// If we are changing the source from MIDI, disable the serial interrupt
|
||||
// handler.
|
||||
if (source_ == SOURCE_EXTERNAL_MIDI) {
|
||||
NeoSerial.attachInterrupt(serialEventNoop);
|
||||
}
|
||||
|
||||
// Handle external clock tick and call user callback when receiving clock trigger (PPQN_4, PPQN_24, or MIDI).
|
||||
void AttachExtHandler(void (*callback)()) {
|
||||
extUserCallback = callback;
|
||||
attachInterrupt(digitalPinToInterrupt(EXT_PIN), callback, RISING);
|
||||
source_ = source;
|
||||
switch (source) {
|
||||
case SOURCE_INTERNAL:
|
||||
uClock.setClockMode(uClock.INTERNAL_CLOCK);
|
||||
break;
|
||||
case SOURCE_EXTERNAL_PPQN_24:
|
||||
uClock.setClockMode(uClock.EXTERNAL_CLOCK);
|
||||
uClock.setInputPPQN(uClock.PPQN_24);
|
||||
break;
|
||||
case SOURCE_EXTERNAL_PPQN_4:
|
||||
uClock.setClockMode(uClock.EXTERNAL_CLOCK);
|
||||
uClock.setInputPPQN(uClock.PPQN_4);
|
||||
break;
|
||||
case SOURCE_EXTERNAL_PPQN_2:
|
||||
uClock.setClockMode(uClock.EXTERNAL_CLOCK);
|
||||
uClock.setInputPPQN(uClock.PPQN_2);
|
||||
break;
|
||||
case SOURCE_EXTERNAL_PPQN_1:
|
||||
uClock.setClockMode(uClock.EXTERNAL_CLOCK);
|
||||
uClock.setInputPPQN(uClock.PPQN_1);
|
||||
break;
|
||||
case SOURCE_EXTERNAL_MIDI:
|
||||
uClock.setClockMode(uClock.EXTERNAL_CLOCK);
|
||||
uClock.setInputPPQN(uClock.PPQN_24);
|
||||
NeoSerial.attachInterrupt(onSerialEvent);
|
||||
break;
|
||||
}
|
||||
|
||||
// Internal PPQN96 callback for all clock timer operations.
|
||||
void AttachIntHandler(void (*callback)(uint32_t)) {
|
||||
uClock.setOnOutputPPQN(callback);
|
||||
if (was_playing) {
|
||||
uClock.start();
|
||||
}
|
||||
}
|
||||
|
||||
// Set the source of the clock mode.
|
||||
void SetSource(Source source) {
|
||||
bool was_playing = !IsPaused();
|
||||
uClock.stop();
|
||||
// If we are changing the source from MIDI, disable the serial interrupt handler.
|
||||
if (source_ == SOURCE_EXTERNAL_MIDI) {
|
||||
NeoSerial.attachInterrupt(serialEventNoop);
|
||||
}
|
||||
source_ = source;
|
||||
switch (source) {
|
||||
case SOURCE_INTERNAL:
|
||||
uClock.setClockMode(uClock.INTERNAL_CLOCK);
|
||||
break;
|
||||
case SOURCE_EXTERNAL_PPQN_24:
|
||||
uClock.setClockMode(uClock.EXTERNAL_CLOCK);
|
||||
uClock.setInputPPQN(uClock.PPQN_24);
|
||||
break;
|
||||
case SOURCE_EXTERNAL_PPQN_4:
|
||||
uClock.setClockMode(uClock.EXTERNAL_CLOCK);
|
||||
uClock.setInputPPQN(uClock.PPQN_4);
|
||||
break;
|
||||
case SOURCE_EXTERNAL_PPQN_1:
|
||||
uClock.setClockMode(uClock.EXTERNAL_CLOCK);
|
||||
uClock.setInputPPQN(uClock.PPQN_1);
|
||||
break;
|
||||
case SOURCE_EXTERNAL_MIDI:
|
||||
uClock.setClockMode(uClock.EXTERNAL_CLOCK);
|
||||
uClock.setInputPPQN(uClock.PPQN_24);
|
||||
NeoSerial.attachInterrupt(onSerialEvent);
|
||||
break;
|
||||
}
|
||||
if (was_playing) {
|
||||
uClock.start();
|
||||
}
|
||||
// Return true if the current selected source is externl (PPQN_4, PPQN_24, or
|
||||
// MIDI).
|
||||
bool ExternalSource() {
|
||||
return uClock.getClockMode() == uClock.EXTERNAL_CLOCK;
|
||||
}
|
||||
|
||||
// Return true if the current selected source is the internal master clock.
|
||||
bool InternalSource() {
|
||||
return uClock.getClockMode() == uClock.INTERNAL_CLOCK;
|
||||
}
|
||||
|
||||
// Returns the current BPM tempo.
|
||||
int Tempo() { return uClock.getTempo(); }
|
||||
|
||||
// Set the clock tempo to a int between 1 and 400.
|
||||
void SetTempo(int tempo) { return uClock.setTempo(tempo); }
|
||||
|
||||
// Record an external clock tick received to process external/internal
|
||||
// syncronization.
|
||||
void Tick() { uClock.clockMe(); }
|
||||
|
||||
// Start the internal clock.
|
||||
void Start() { uClock.start(); }
|
||||
|
||||
// Stop internal clock clock.
|
||||
void Stop() { uClock.stop(); }
|
||||
|
||||
// Reset all clock counters to 0.
|
||||
void Reset() { uClock.resetCounters(); }
|
||||
|
||||
// Returns true if the clock is not running.
|
||||
bool IsPaused() { return uClock.clock_state == uClock.PAUSED; }
|
||||
|
||||
private:
|
||||
Source source_ = SOURCE_INTERNAL;
|
||||
|
||||
static void onSerialEvent(uint8_t msg, uint8_t status) {
|
||||
// Note: uClock start and stop will echo to MIDI.
|
||||
switch (msg) {
|
||||
case MIDI_CLOCK:
|
||||
if (extUserCallback) {
|
||||
extUserCallback();
|
||||
}
|
||||
break;
|
||||
case MIDI_STOP:
|
||||
uClock.stop();
|
||||
sendMIDIStop();
|
||||
break;
|
||||
case MIDI_START:
|
||||
case MIDI_CONTINUE:
|
||||
uClock.start();
|
||||
sendMIDIStart();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Return true if the current selected source is externl (PPQN_4, PPQN_24, or MIDI).
|
||||
bool ExternalSource() {
|
||||
return uClock.getClockMode() == uClock.EXTERNAL_CLOCK;
|
||||
}
|
||||
static void sendMIDIStart() { NeoSerial.write(MIDI_START); }
|
||||
|
||||
// Return true if the current selected source is the internal master clock.
|
||||
bool InternalSource() {
|
||||
return uClock.getClockMode() == uClock.INTERNAL_CLOCK;
|
||||
}
|
||||
static void sendMIDIStop() { NeoSerial.write(MIDI_STOP); }
|
||||
|
||||
// Returns the current BPM tempo.
|
||||
int Tempo() {
|
||||
return uClock.getTempo();
|
||||
}
|
||||
|
||||
// Set the clock tempo to a int between 1 and 400.
|
||||
void SetTempo(int tempo) {
|
||||
return uClock.setTempo(tempo);
|
||||
}
|
||||
|
||||
// Record an external clock tick received to process external/internal syncronization.
|
||||
void Tick() {
|
||||
uClock.clockMe();
|
||||
}
|
||||
|
||||
// Start the internal clock.
|
||||
void Start() {
|
||||
uClock.start();
|
||||
}
|
||||
|
||||
// Stop internal clock clock.
|
||||
void Stop() {
|
||||
uClock.stop();
|
||||
}
|
||||
|
||||
// Reset all clock counters to 0.
|
||||
void Reset() {
|
||||
uClock.resetCounters();
|
||||
}
|
||||
|
||||
// Returns true if the clock is not running.
|
||||
bool IsPaused() {
|
||||
return uClock.clock_state == uClock.PAUSED;
|
||||
}
|
||||
|
||||
private:
|
||||
Source source_ = SOURCE_INTERNAL;
|
||||
|
||||
static void onSerialEvent(uint8_t msg, uint8_t status) {
|
||||
// Note: uClock start and stop will echo to MIDI.
|
||||
switch (msg) {
|
||||
case MIDI_CLOCK:
|
||||
if (extUserCallback) {
|
||||
extUserCallback();
|
||||
}
|
||||
break;
|
||||
case MIDI_STOP:
|
||||
uClock.stop();
|
||||
sendMIDIStop();
|
||||
break;
|
||||
case MIDI_START:
|
||||
case MIDI_CONTINUE:
|
||||
uClock.start();
|
||||
sendMIDIStart();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void sendMIDIStart() {
|
||||
NeoSerial.write(MIDI_START);
|
||||
}
|
||||
|
||||
static void sendMIDIStop() {
|
||||
NeoSerial.write(MIDI_STOP);
|
||||
}
|
||||
|
||||
static void sendMIDIClock(uint32_t tick) {
|
||||
NeoSerial.write(MIDI_CLOCK);
|
||||
}
|
||||
static void sendMIDIClock(uint32_t tick) { NeoSerial.write(MIDI_CLOCK); }
|
||||
};
|
||||
|
||||
#endif
|
||||
@ -2,9 +2,9 @@
|
||||
* @file digital_output.h
|
||||
* @author Adam Wonak (https://github.com/awonak)
|
||||
* @brief Class for interacting with trigger / gate outputs.
|
||||
* @version 2.0.0
|
||||
* @date 2025-08-17
|
||||
*
|
||||
* @version 0.1
|
||||
* @date 2025-04-17
|
||||
*
|
||||
* @copyright MIT - (c) 2025 - Adam Wonak - adam.wonak@gmail.com
|
||||
*
|
||||
*/
|
||||
@ -16,78 +16,81 @@
|
||||
const byte DEFAULT_TRIGGER_DURATION_MS = 5;
|
||||
|
||||
class DigitalOutput {
|
||||
public:
|
||||
/**
|
||||
* Initializes an CV Output paired object.
|
||||
*
|
||||
* @param cv_pin gpio pin for the cv output
|
||||
*/
|
||||
void Init(uint8_t cv_pin) {
|
||||
pinMode(cv_pin, OUTPUT); // Gate/Trigger Output
|
||||
cv_pin_ = cv_pin;
|
||||
trigger_duration_ = DEFAULT_TRIGGER_DURATION_MS;
|
||||
public:
|
||||
/**
|
||||
* Initializes an CV Output paired object.
|
||||
*
|
||||
* @param cv_pin gpio pin for the cv output
|
||||
*/
|
||||
void Init(uint8_t cv_pin) {
|
||||
pinMode(cv_pin, OUTPUT); // Gate/Trigger Output
|
||||
cv_pin_ = cv_pin;
|
||||
trigger_duration_ = DEFAULT_TRIGGER_DURATION_MS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the trigger duration in miliseconds.
|
||||
*
|
||||
* @param duration_ms trigger duration in miliseconds
|
||||
*/
|
||||
void SetTriggerDuration(uint8_t duration_ms) {
|
||||
trigger_duration_ = duration_ms;
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn the CV and LED on or off according to the input state.
|
||||
*
|
||||
* @param state Arduino digital HIGH or LOW values.
|
||||
*/
|
||||
inline void Update(uint8_t state) {
|
||||
if (state == HIGH)
|
||||
High(); // Rising
|
||||
if (state == LOW)
|
||||
Low(); // Falling
|
||||
}
|
||||
|
||||
// Sets the cv output HIGH to about 5v.
|
||||
inline void High() { update(HIGH); }
|
||||
|
||||
// Sets the cv output LOW to 0v.
|
||||
inline void Low() { update(LOW); }
|
||||
|
||||
/**
|
||||
* Begin a Trigger period for this output.
|
||||
*/
|
||||
inline void Trigger() {
|
||||
update(HIGH);
|
||||
last_triggered_ = millis();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a bool representing the on/off state of the output.
|
||||
*/
|
||||
inline void Process() {
|
||||
// If trigger is HIGH and the trigger duration time has elapsed, set the
|
||||
// output low.
|
||||
if (on_ && (millis() - last_triggered_) >= trigger_duration_) {
|
||||
update(LOW);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the trigger duration in miliseconds.
|
||||
*
|
||||
* @param duration_ms trigger duration in miliseconds
|
||||
*/
|
||||
void SetTriggerDuration(uint8_t duration_ms) {
|
||||
trigger_duration_ = duration_ms;
|
||||
}
|
||||
/**
|
||||
* Return a bool representing the on/off state of the output.
|
||||
*
|
||||
* @return true if current cv state is high, false if current cv state is low
|
||||
*/
|
||||
inline bool On() { return on_; }
|
||||
|
||||
/**
|
||||
* Turn the CV and LED on or off according to the input state.
|
||||
*
|
||||
* @param state Arduino digital HIGH or LOW values.
|
||||
*/
|
||||
inline void Update(uint8_t state) {
|
||||
if (state == HIGH) High(); // Rising
|
||||
if (state == LOW) Low(); // Falling
|
||||
}
|
||||
private:
|
||||
unsigned long last_triggered_;
|
||||
uint8_t trigger_duration_;
|
||||
uint8_t cv_pin_;
|
||||
bool on_;
|
||||
|
||||
// Sets the cv output HIGH to about 5v.
|
||||
inline void High() { update(HIGH); }
|
||||
|
||||
// Sets the cv output LOW to 0v.
|
||||
inline void Low() { update(LOW); }
|
||||
|
||||
/**
|
||||
* Begin a Trigger period for this output.
|
||||
*/
|
||||
inline void Trigger() {
|
||||
update(HIGH);
|
||||
last_triggered_ = millis();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a bool representing the on/off state of the output.
|
||||
*/
|
||||
inline void Process() {
|
||||
// If trigger is HIGH and the trigger duration time has elapsed, set the output low.
|
||||
if (on_ && (millis() - last_triggered_) >= trigger_duration_) {
|
||||
update(LOW);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a bool representing the on/off state of the output.
|
||||
*
|
||||
* @return true if current cv state is high, false if current cv state is low
|
||||
*/
|
||||
inline bool On() { return on_; }
|
||||
|
||||
private:
|
||||
unsigned long last_triggered_;
|
||||
uint8_t trigger_duration_;
|
||||
uint8_t cv_pin_;
|
||||
bool on_;
|
||||
|
||||
void update(uint8_t state) {
|
||||
digitalWrite(cv_pin_, state);
|
||||
on_ = state == HIGH;
|
||||
}
|
||||
void update(uint8_t state) {
|
||||
digitalWrite(cv_pin_, state);
|
||||
on_ = state == HIGH;
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@ -2,8 +2,8 @@
|
||||
* @file encoder_dir.h
|
||||
* @author Adam Wonak (https://github.com/awonak)
|
||||
* @brief Class for interacting with encoders.
|
||||
* @version 2.0.0
|
||||
* @date 2025-08-17
|
||||
* @version 0.1
|
||||
* @date 2025-04-19
|
||||
*
|
||||
* @copyright MIT - (c) 2025 - Adam Wonak - adam.wonak@gmail.com
|
||||
*
|
||||
|
||||
@ -2,8 +2,8 @@
|
||||
* @file libGravity.cpp
|
||||
* @author Adam Wonak (https://github.com/awonak)
|
||||
* @brief Library for building custom scripts for the Sitka Instruments Gravity module.
|
||||
* @version 2.0.0
|
||||
* @date 2025-08-17
|
||||
* @version 0.1
|
||||
* @date 2025-04-19
|
||||
*
|
||||
* @copyright MIT - (c) 2025 - Adam Wonak - adam.wonak@gmail.com
|
||||
*
|
||||
|
||||
@ -2,8 +2,8 @@
|
||||
* @file libGravity.h
|
||||
* @author Adam Wonak (https://github.com/awonak)
|
||||
* @brief Library for building custom scripts for the Sitka Instruments Gravity module.
|
||||
* @version 2.0.0
|
||||
* @date 2025-08-17
|
||||
* @version 0.1
|
||||
* @date 2025-04-19
|
||||
*
|
||||
* @copyright MIT - (c) 2025 - Adam Wonak - adam.wonak@gmail.com
|
||||
*
|
||||
|
||||
@ -2,8 +2,8 @@
|
||||
* @file peripherials.h
|
||||
* @author Adam Wonak (https://github.com/awonak)
|
||||
* @brief Arduino pin definitions for the Sitka Instruments Gravity module.
|
||||
* @version 2.0.0
|
||||
* @date 2025-08-17
|
||||
* @version 0.1
|
||||
* @date 2025-04-19
|
||||
*
|
||||
* @copyright MIT - (c) 2025 - Adam Wonak - adam.wonak@gmail.com
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user