GY-63_MS5611/libraries/FunctionGenerator/examples/functionGenerator/functionGenerator.ino

63 lines
1.2 KiB
Arduino
Raw Normal View History

2016-12-17 14:57:37 -05:00
//
// FILE: functionGenerator.ino
// AUTHOR: Rob Tillaart
// PURPOSE: demo function generators
// DATE: 2015-01-03
2020-11-27 05:16:22 -05:00
// URL: https://github.com/RobTillaart/FunctionGenerator
2016-12-17 14:57:37 -05:00
//
2021-11-02 06:27:01 -04:00
2016-12-17 14:57:37 -05:00
#include "functionGenerator.h"
2021-11-02 06:27:01 -04:00
2020-11-27 05:16:22 -05:00
funcgen gen;
2016-12-17 14:57:37 -05:00
uint32_t lastTime = 0;
2020-11-27 05:16:22 -05:00
char choice = '0';
2016-12-17 14:57:37 -05:00
2021-11-02 06:27:01 -04:00
2016-12-17 14:57:37 -05:00
void setup()
{
2020-11-27 05:16:22 -05:00
Serial.begin(500000);
Serial.println(__FILE__);
2016-12-17 14:57:37 -05:00
Serial.println("Start ");
2020-11-27 05:16:22 -05:00
gen.setFrequency(4);
gen.setAmplitude(50);
2016-12-17 14:57:37 -05:00
}
2021-11-02 06:27:01 -04:00
2016-12-17 14:57:37 -05:00
void loop()
{
2020-11-27 05:16:22 -05:00
if (Serial.available())
{
choice = Serial.read();
}
// wave selection by potMeter
// int choice = analogRead(A0) / 200;
2016-12-17 14:57:37 -05:00
2021-12-18 10:52:23 -05:00
float value;
2020-11-27 05:16:22 -05:00
// wait for next millisecond;
if (millis() - lastTime > 0)
2016-12-17 14:57:37 -05:00
{
2020-11-27 05:16:22 -05:00
lastTime = millis();
float t = lastTime * 0.001;
2016-12-17 14:57:37 -05:00
switch (choice)
{
2021-12-18 10:52:23 -05:00
case '0': value = gen.square(t); break;
case '1': value = gen.sawtooth(t); break;
case '2': value = gen.triangle(t); break;
case '3': value = gen.stair(t); break;
case '4': value = gen.sinus(t); break;
case '5': value = gen.line(); break;
case '6': value = gen.random(); break;
default: value = gen.zero(); break;
2016-12-17 14:57:37 -05:00
}
2021-12-18 10:52:23 -05:00
Serial.println(value);
2016-12-17 14:57:37 -05:00
}
}
2021-11-02 06:27:01 -04:00
// -- END OF FILE --