Skip to content

Commit 0f395d8

Browse files
committed
Basic plotting example
1 parent 8079a7c commit 0f395d8

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
Plotting example
3+
4+
In this example we generate a continous sine wave
5+
on the arduino and send it out via the serial port.
6+
This signal can be observed via the serial plotter
7+
of the Arduino IDE.
8+
9+
This example code is in the public domain.
10+
*/
11+
12+
float frequency = 1.0f;
13+
float amplitude = 100.0f;
14+
15+
void setup() {
16+
// Initialize serial
17+
Serial.begin(115200);
18+
}
19+
20+
void loop() {
21+
unsigned long time = millis();
22+
23+
// Compute basic sine wave signal
24+
float x = time * 0.001f * 2 * PI * frequency;
25+
float signal = amplitude * sin(x);
26+
27+
// Adding some random noise to the signal
28+
signal += random(-100, 101) * 0.0006f * amplitude;
29+
30+
// Send the signal over the serial
31+
Serial.println(signal);
32+
33+
// Wait for 10ms to limit the update rate
34+
delay(10);
35+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This sketch programs the Arduino to generate a sine wave which is send back to the IDE to be plotted there.

0 commit comments

Comments
 (0)