mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
add examples
This commit is contained in:
parent
c55a0c89ea
commit
3b5211350b
@ -0,0 +1,45 @@
|
||||
//
|
||||
// FILE: RunningMedian.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// PURPOSE: array of runningMedian objects
|
||||
// DATE: 2022-06-21
|
||||
// URL: https://github.com/RobTillaart/RunningMedian
|
||||
|
||||
|
||||
#include <RunningMedian.h>
|
||||
|
||||
RunningMedian a(5);
|
||||
RunningMedian b(10);
|
||||
RunningMedian c(15);
|
||||
RunningMedian d(20);
|
||||
|
||||
RunningMedian RM[4] = { a, b, c, d };
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.print("Running Median Version: ");
|
||||
Serial.println(RUNNING_MEDIAN_VERSION);
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
RM[i].add(random(100));
|
||||
}
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
Serial.print(RM[i].getCount());
|
||||
Serial.print("\t");
|
||||
Serial.print(RM[i].getMedian());
|
||||
Serial.print("\t");
|
||||
}
|
||||
Serial.println();
|
||||
delay(100);
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
@ -0,0 +1,46 @@
|
||||
//
|
||||
// FILE: RunningMedian_array_pointer.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// PURPOSE: array of runningMedian objects
|
||||
// DATE: 2022-06-21
|
||||
// URL: https://github.com/RobTillaart/RunningMedian
|
||||
|
||||
|
||||
#include <RunningMedian.h>
|
||||
|
||||
|
||||
RunningMedian *RM[4]; // array of 4 pointers to RM objects
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.print("Running Median Version: ");
|
||||
Serial.println(RUNNING_MEDIAN_VERSION);
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
RM[i] = new RunningMedian(3 + i*3); // let the pointers point to a new RM object.
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
RM[i]->add(random(100));
|
||||
}
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
Serial.print(RM[i]->getCount());
|
||||
Serial.print("\t");
|
||||
Serial.print(RM[i]->getMedian());
|
||||
Serial.print("\t");
|
||||
}
|
||||
Serial.println();
|
||||
delay(100);
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
Loading…
x
Reference in New Issue
Block a user