Skip to content

Commit

Permalink
Add frequency_t
Browse files Browse the repository at this point in the history
  • Loading branch information
bblanchon committed Sep 2, 2023
1 parent 768db68 commit a947c4f
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/ContinuousStepper/Tickers/AnalogWriteFrequency.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class AwfOscillator {
pin_ = pin;
}

void start(unsigned int frequency) {
void start(frequency_t frequency) {
analogWriteFrequency(pin_, frequency);
if (!active_) {
analogWrite(pin_, 128);
Expand All @@ -24,7 +24,7 @@ class AwfOscillator {
active_ = false;
}

unsigned int minFrequency() const {
frequency_t minFrequency() const {
// The analogWriteFrequency function has a lower limit of a few Hz.
// https://www.pjrc.com/teensy/td_pulse.html#frequency
return 5;
Expand Down
4 changes: 2 additions & 2 deletions src/ContinuousStepper/Tickers/KhoiH_PWM.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ class KhoihOscillator {
pwm_ = new KhoiH_PWM(pin, 500, 0);
}

void start(unsigned int frequency) {
void start(frequency_t frequency) {
pwm_->setPWM(pin_, frequency, 50);
}

void stop() {
pwm_->setPWM(pin_, 500, 0);
}

unsigned int minFrequency() const {
frequency_t minFrequency() const {
return 1;
}

Expand Down
2 changes: 2 additions & 0 deletions src/ContinuousStepper/Tickers/OscillatorTicker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace ArduinoContinuousStepper {

using frequency_t = unsigned int;

template <class TOscillator>
class OscillatorTicker : StepperTicker {
using time_t = unsigned long;
Expand Down
4 changes: 2 additions & 2 deletions src/ContinuousStepper/Tickers/Tone.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ class ToneOscillator {
pin_ = pin;
}

void start(unsigned int frequency) {
void start(frequency_t frequency) {
tone(pin_, frequency);
}

void stop() {
noTone(pin_);
}

unsigned int minFrequency() const {
frequency_t minFrequency() const {
#if defined(ARDUINO_ARCH_AVR)
// It is not possible to generate tones lower than 31Hz
// https://www.arduino.cc/reference/en/language/functions/advanced-io/tone/
Expand Down

0 comments on commit a947c4f

Please sign in to comment.