-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathfunctionGenerator.ino
More file actions
65 lines (51 loc) · 1.31 KB
/
functionGenerator.ino
File metadata and controls
65 lines (51 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//
// FILE: functionGenerator.ino
// AUTHOR: Rob Tillaart
// PURPOSE: demo function generators
// DATE: 2015-01-03
// URL: https://github.com/RobTillaart/FunctionGenerator
#include "functionGenerator.h"
funcgen gen;
uint32_t lastTime = 0;
char choice = '0';
void setup()
{
Serial.begin(500000);
Serial.println();
Serial.println(__FILE__);
Serial.println("FUNCTIONGENERATOR_LIB_VERSION: ");
Serial.println(FUNCTIONGENERATOR_LIB_VERSION);
Serial.println();
Serial.println("Start ");
gen.setFrequency(4);
gen.setAmplitude(50);
}
void loop()
{
if (Serial.available())
{
choice = Serial.read();
}
// wave selection by potMeter
// int choice = analogRead(A0) / 200;
float value;
// wait for next millisecond;
if (millis() - lastTime > 0)
{
lastTime = millis();
float t = lastTime * 0.001;
switch (choice)
{
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;
}
Serial.println(value);
}
}
// -- END OF FILE --