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

58 lines
1.2 KiB
Arduino
Raw Normal View History

2016-12-17 14:57:37 -05:00
//
// FILE: functionGenerator.ino
// AUTHOR: Rob Tillaart
2020-11-27 05:16:22 -05:00
// VERSION: 0.2.0
2016-12-17 14:57:37 -05:00
// 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
//
#include "functionGenerator.h"
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
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
}
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
float val;
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)
{
2020-11-27 05:16:22 -05:00
case '0': val = gen.square(t); break;
case '1': val = gen.sawtooth(t); break;
case '2': val = gen.triangle(t); break;
case '3': val = gen.stair(t); break;
case '4': val = gen.sinus(t); break;
case '5': val = gen.line(); break;
case '6': val = gen.random(); break;
default: val = gen.zero(); break;
2016-12-17 14:57:37 -05:00
}
Serial.println(val);
}
}
// END OF FILE