2020-11-27 05:16:22 -05:00
|
|
|
#pragma once
|
2016-12-17 14:57:37 -05:00
|
|
|
//
|
|
|
|
// FILE: functionGenerator.h
|
|
|
|
// AUTHOR: Rob Tillaart
|
2022-11-07 09:28:23 -05:00
|
|
|
// VERSION: 0.2.4
|
2020-11-27 05:16:22 -05:00
|
|
|
// PURPOSE: wave form generating functions (use with care)
|
|
|
|
// URL: https://github.com/RobTillaart/FunctionGenerator
|
2016-12-17 14:57:37 -05:00
|
|
|
//
|
|
|
|
|
2021-11-02 06:27:01 -04:00
|
|
|
|
2020-11-27 05:16:22 -05:00
|
|
|
#include "Arduino.h"
|
2016-12-17 14:57:37 -05:00
|
|
|
|
2022-11-07 09:28:23 -05:00
|
|
|
#define FUNCTIONGENERATOR_LIB_VERSION (F("0.2.4"))
|
2021-11-02 06:27:01 -04:00
|
|
|
|
2016-12-17 14:57:37 -05:00
|
|
|
|
|
|
|
class funcgen
|
|
|
|
{
|
|
|
|
public:
|
2020-11-27 05:16:22 -05:00
|
|
|
funcgen(float period = 1.0, float amplitude = 1.0, float phase = 0.0, float yShift = 0.0);
|
|
|
|
|
|
|
|
// configuration
|
|
|
|
void setPeriod(float period = 1.0);
|
|
|
|
float getPeriod() { return _period; };
|
|
|
|
void setFrequency(float freq = 1.0) { setPeriod(1/freq); };
|
|
|
|
float getFrequency() { return _freq1; };
|
2021-11-02 06:27:01 -04:00
|
|
|
|
2020-11-27 05:16:22 -05:00
|
|
|
void setAmplitude(float ampl = 1.0) { _amplitude = ampl; };
|
|
|
|
float getAmplitude() { return _amplitude; };
|
|
|
|
void setPhase(float phase = 0.0) { _phase = phase; };
|
|
|
|
float getPhase() { return _phase; };
|
|
|
|
void setYShift(float yShift = 0.0) { _yShift = yShift; };
|
|
|
|
float getYShift() { return _yShift; };
|
|
|
|
|
|
|
|
// constant amplitude
|
|
|
|
float line();
|
|
|
|
// constant zero for calibration
|
|
|
|
float zero();
|
|
|
|
|
|
|
|
// standard wave forms
|
2021-11-02 06:27:01 -04:00
|
|
|
float sawtooth(float t, uint8_t mode = 0);
|
2020-11-27 05:16:22 -05:00
|
|
|
float triangle(float t);
|
|
|
|
float square(float t);
|
|
|
|
float sinus(float t);
|
2021-11-02 06:27:01 -04:00
|
|
|
float stair(float t, uint16_t steps = 8, uint8_t mode = 0);
|
2020-11-27 05:16:22 -05:00
|
|
|
float random();
|
2016-12-17 14:57:37 -05:00
|
|
|
|
|
|
|
private:
|
2020-11-27 05:16:22 -05:00
|
|
|
float _period;
|
|
|
|
float _freq0;
|
|
|
|
float _freq1;
|
|
|
|
float _freq2;
|
|
|
|
float _freq4;
|
|
|
|
float _amplitude;
|
|
|
|
float _phase;
|
|
|
|
float _yShift;
|
|
|
|
// Marsaglia 'constants'
|
|
|
|
uint32_t _m_w = 1;
|
|
|
|
uint32_t _m_z = 2;
|
|
|
|
uint32_t _random();
|
2016-12-17 14:57:37 -05:00
|
|
|
};
|
|
|
|
|
2021-11-02 06:27:01 -04:00
|
|
|
|
|
|
|
// -- END OF FILE --
|
|
|
|
|