GY-63_MS5611/libraries/FunctionGenerator/FunctionGenerator.h

86 lines
1.7 KiB
C
Raw Normal View History

2020-11-27 05:16:22 -05:00
#pragma once
2016-12-17 14:57:37 -05:00
//
// FILE: functionGenerator.h
// AUTHOR: Rob Tillaart
2023-11-02 10:09:32 -04:00
// VERSION: 0.2.6
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
2023-11-02 10:09:32 -04:00
#define FUNCTIONGENERATOR_LIB_VERSION (F("0.2.6"))
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);
2023-03-26 04:32:34 -04:00
/////////////////////////////////////////////////////////////
//
// CONFIGURATION
//
2020-11-27 05:16:22 -05:00
void setPeriod(float period = 1.0);
2023-03-26 04:32:34 -04:00
float getPeriod();
void setFrequency(float freq = 1.0);
float getFrequency();
void setAmplitude(float ampl = 1.0);
float getAmplitude();
void setPhase(float phase = 0.0);
float getPhase();
void setYShift(float yShift = 0.0);
float getYShift();
void setDutyCycle(float dutyCycle);
float getDutyCycle();
void setRandomSeed(uint32_t a, uint32_t b = 314159265);
/////////////////////////////////////////////////////////////
//
// FUNCTIONS
//
// constant amplitude
2020-11-27 05:16:22 -05:00
float line();
2023-03-26 04:32:34 -04:00
// constant zero for calibration.
2020-11-27 05:16:22 -05:00
float zero();
2023-03-26 04:32:34 -04:00
// standard wave forms
float sawtooth(float t, uint8_t mode = 0); // 0 ==> /|. 1 ==> sawtooth |\.
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);
2023-03-26 04:32:34 -04:00
2020-11-27 05:16:22 -05:00
float random();
2023-03-26 04:32:34 -04:00
float random_DC(); // duty cycle variant. Experimental.
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;
2023-03-26 04:32:34 -04:00
float _dutyCycle;
// Marsaglia 'constants'
2020-11-27 05:16:22 -05:00
uint32_t _m_w = 1;
2023-03-26 04:32:34 -04:00
uint32_t _m_z = 2;
2020-11-27 05:16:22 -05:00
uint32_t _random();
2016-12-17 14:57:37 -05:00
};
2021-11-02 06:27:01 -04:00
2023-03-26 04:32:34 -04:00
// -- END OF FILE --
2021-11-02 06:27:01 -04:00