Skip to content

Commit

Permalink
added partials example
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandreHiroyuki committed May 16, 2022
1 parent d628939 commit 79e8c37
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 5 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
[![Contributors](https://img.shields.io/github/contributors-anon/AlexandreHiroyuki/MovingAveragePlus)](https://github.com/AlexandreHiroyuki/MovingAveragePlus/graphs/contributors)
[![Top Language](https://img.shields.io/github/languages/top/AlexandreHiroyuki/MovingAveragePlus)](https://github.com/AlexandreHiroyuki/MovingAveragePlus)

> _Old name: MovingAverage_ArduinoLibrary_
A C++ library that implements a moving average on the Arduino platform. Performance and usability are the two focuses I thought of when creating this library, so every improving tip is welcome.

This library is listed in the official [Arduino Library Manager](https://www.arduino.cc/reference/en/libraries/moving-average-plus/), and you can also find it at [Arduino Library List](https://www.arduinolibraries.info/libraries/moving-average-plus).
Expand Down
46 changes: 46 additions & 0 deletions examples/partials_example/partials_example.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Include lib:
#include <MovingAveragePlus.h>

// Create an Arithmetic Moving Average object of unsigned int type,
// 10 in size
MovingAveragePlus<unsigned> integer_mv(10);

// This variable just generates input for average integer_mv
unsigned delta_x = 0;

// These variables are the identification of the integer_mv partials
size_t integer_mv_partial_id = 0;
size_t integer_mv_partial_id_2 = 0;

void setup() {
// Initialize serial interface
Serial.begin(9600);

integer_mv_partial_id = integer_mv.create_partial(3);
integer_mv_partial_id_2 = integer_mv.create_partial(5);
}

void loop() {
// Pushes the input in the moving average object
integer_mv.push(delta_x);

// Generates the next input
delta_x += 5;
if (delta_x > 1000) delta_x = 0;

// Prints each value stored in the moving average
for (uint8_t i = 0; i < integer_mv.size(); i++) {
Serial.print(integer_mv[i]);
Serial.print(" ");
}
// Prints the result of the average
Serial.print("= ");
Serial.print(integer_mv.get());
// Prints the value stored in the partials
Serial.print(" | p(3): ");
Serial.print(integer_mv.get_partial(integer_mv_partial_id));
Serial.print(" p(5): ");
Serial.println(integer_mv.get_partial(integer_mv_partial_id_2));

delay(1000);
}
4 changes: 2 additions & 2 deletions library.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "MovingAveragePlus",
"version": "4.1.4",
"description": "Moving Average Plus implements a lightweight moving average structure on Arduino. Performance and usability are the two focuses I thought of when creating this library.",
"version": "4.2.0",
"description": "Moving Average Plus implements a lightweight moving average structure on Arduino. Fully documented. Performance and usability are the two focuses I thought of when creating this library.",
"keywords": "sensors, input, data, processing, arduino, library, iot, filter, moving average, smooth, moving, average",
"repository": {
"type": "git",
Expand Down
6 changes: 3 additions & 3 deletions library.properties
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name=MovingAveragePlus
version=4.1.4
version=4.2.0
author=Alexandre Hiroyuki Yamauchi <[email protected]>
maintainer=Alexandre Hiroyuki Yamauchi <[email protected]>
sentence=Moving Average library for Arduino
paragraph=Implements a lightweight moving average structure on Arduino. Performance and usability are the two focuses I thought of when creating this library.
sentence=Moving Average library compatible with any number type
paragraph=Fully documented. Implements a lightweight moving average structure on Arduino. Performance and usability are the two focuses I thought of when creating this library.
category=Data Processing
url=https://github.com/AlexandreHiroyuki/MovingAveragePlus
architectures=*

0 comments on commit 79e8c37

Please sign in to comment.