Skip to content

Commit

Permalink
Basic plotting example
Browse files Browse the repository at this point in the history
  • Loading branch information
henningpohl committed Jul 2, 2015
1 parent 8079a7c commit 0f395d8
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
35 changes: 35 additions & 0 deletions build/shared/examples/01.Basics/Plotting/Plotting.ino
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);
}
1 change: 1 addition & 0 deletions build/shared/examples/01.Basics/Plotting/Plotting.txt
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.

0 comments on commit 0f395d8

Please sign in to comment.