forked from arduino/Arduino
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8079a7c
commit 0f395d8
Showing
2 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
Plotting example | ||
In this example we generate a continous sine wave | ||
on the arduino and send it out via the serial port. | ||
This signal can be observed via the serial plotter | ||
of the Arduino IDE. | ||
This example code is in the public domain. | ||
*/ | ||
|
||
float frequency = 1.0f; | ||
float amplitude = 100.0f; | ||
|
||
void setup() { | ||
// Initialize serial | ||
Serial.begin(115200); | ||
} | ||
|
||
void loop() { | ||
unsigned long time = millis(); | ||
|
||
// Compute basic sine wave signal | ||
float x = time * 0.001f * 2 * PI * frequency; | ||
float signal = amplitude * sin(x); | ||
|
||
// Adding some random noise to the signal | ||
signal += random(-100, 101) * 0.0006f * amplitude; | ||
|
||
// Send the signal over the serial | ||
Serial.println(signal); | ||
|
||
// Wait for 10ms to limit the update rate | ||
delay(10); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
This sketch programs the Arduino to generate a sine wave which is send back to the IDE to be plotted there. |