File tree 2 files changed +36
-0
lines changed
build/shared/examples/01.Basics/Plotting
2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
1
+ This sketch programs the Arduino to generate a sine wave which is send back to the IDE to be plotted there.
You can’t perform that action at this time.
0 commit comments