Skip to content

Commit

Permalink
Arduino
Browse files Browse the repository at this point in the history
  • Loading branch information
pilotak committed Jul 29, 2018
1 parent 05e72b0 commit ef350ac
Show file tree
Hide file tree
Showing 5 changed files with 176 additions and 3 deletions.
4 changes: 3 additions & 1 deletion Hysteresis.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ SOFTWARE.
#ifndef HYSTERESIS_H
#define HYSTERESIS_H

#include "mbed.h"
#if defined(__MBED__)
#include "mbed.h"
#endif

template <class T>
class Hysteresis {
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Hysteresis
Fixed point hysteresis filter for Mbed
Fixed point hysteresis filter for Arduino & Mbed

**_Type_** type can be:
- `uint8_t` or `int8_t`
- `uint16_t` or `int16_t`
- `uint32_t` or `int32_t` but only up to 23 bits

# Example
# Mbed example
```cpp
#include "mbed.h"
#include "Hysteresis.h"
Expand Down
155 changes: 155 additions & 0 deletions examples/basic/basic.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
#include "Hysteresis.h"

// Added samples (and result) will be initialised as uint8_t, hysteresis step 10
Hysteresis <uint8_t> hysteresis(10);

void setup() {
Serial.begin(9600);

// or you can change step here
// hysteresis.step(10);

Serial.print("result: 11 = ");
Serial.println(hysteresis.add(11)); // insert new number and get result

Serial.print("result: 12 = ");
Serial.println(hysteresis.add(12)); // insert new number and get result

Serial.print("result: 13 = ");
Serial.println(hysteresis.add(13)); // insert new number and get result

Serial.print("result: 14 = ");
Serial.println(hysteresis.add(14)); // insert new number and get result

Serial.print("result: 15 = ");
Serial.println(hysteresis.add(15)); // insert new number and get result

Serial.print("result: 16 = ");
Serial.println(hysteresis.add(16)); // insert new number and get result

Serial.print("result: 17 = ");
Serial.println(hysteresis.add(17)); // insert new number and get result

Serial.print("result: 18 = ");
Serial.println(hysteresis.add(18)); // insert new number and get result

Serial.print("result: 19 = ");
Serial.println(hysteresis.add(19)); // insert new number and get result

Serial.print("result: 20 = ");
Serial.println(hysteresis.add(20)); // insert new number and get result

Serial.print("result: 21 = ");
Serial.println(hysteresis.add(21)); // insert new number and get result

Serial.print("result: 20 = ");
Serial.println(hysteresis.add(20)); // insert new number and get result

Serial.print("result: 19 = ");
Serial.println(hysteresis.add(19)); // insert new number and get result

Serial.print("result: 18 = ");
Serial.println(hysteresis.add(18)); // insert new number and get result

Serial.print("result: 17 = ");
Serial.println(hysteresis.add(17)); // insert new number and get result

Serial.print("result: 16 = ");
Serial.println(hysteresis.add(16)); // insert new number and get result

Serial.print("result: 15 = ");
Serial.println(hysteresis.add(15)); // insert new number and get result

Serial.print("result: 14 = ");
Serial.println(hysteresis.add(14)); // insert new number and get result

Serial.print("result: 13 = ");
Serial.println(hysteresis.add(13)); // insert new number and get result

Serial.print("result: 12 = ");
Serial.println(hysteresis.add(12)); // insert new number and get result

Serial.print("result: 11 = ");
Serial.println(hysteresis.add(11)); // insert new number and get result

Serial.print("result: 12 = ");
Serial.println(hysteresis.add(12)); // insert new number and get result

Serial.print("result: 13 = ");
Serial.println(hysteresis.add(13)); // insert new number and get result

Serial.print("result: 14 = ");
Serial.println(hysteresis.add(14)); // insert new number and get result

Serial.print("result: 15 = ");
Serial.println(hysteresis.add(15)); // insert new number and get result

Serial.print("result: 16 = ");
Serial.println(hysteresis.add(16)); // insert new number and get result

Serial.print("result: 15 = ");
Serial.println(hysteresis.add(15)); // insert new number and get result

Serial.print("result: 14 = ");
Serial.println(hysteresis.add(14)); // insert new number and get result

Serial.print("result: 15 = ");
Serial.println(hysteresis.add(15)); // insert new number and get result

Serial.print("result: 16 = ");
Serial.println(hysteresis.add(16)); // insert new number and get result

Serial.print("result: 15 = ");
Serial.println(hysteresis.add(15)); // insert new number and get result

Serial.print("result: 14 = ");
Serial.println(hysteresis.add(14)); // insert new number and get result

Serial.print("result: 15 = ");
Serial.println(hysteresis.add(15)); // insert new number and get result

Serial.print("result: 16 = ");
Serial.println(hysteresis.add(16)); // insert new number and get result

Serial.print("result: 17 = ");
Serial.println(hysteresis.add(17)); // insert new number and get result

Serial.print("result: 18 = ");
Serial.println(hysteresis.add(18)); // insert new number and get result

Serial.print("result: 11 = ");
Serial.println(hysteresis.add(17)); // insert new number and get result

Serial.print("result: 16 = ");
Serial.println(hysteresis.add(16)); // insert new number and get result

Serial.print("result: 15 = ");
Serial.println(hysteresis.add(15)); // insert new number and get result

Serial.print("result: 14 = ");
Serial.println(hysteresis.add(14)); // insert new number and get result

Serial.print("result: 15 = ");
Serial.println(hysteresis.add(15)); // insert new number and get result

Serial.print("result: 16 = ");
Serial.println(hysteresis.add(16)); // insert new number and get result

Serial.print("result: 15 = ");
Serial.println(hysteresis.add(15)); // insert new number and get result

Serial.print("result: 14 = ");
Serial.println(hysteresis.add(14)); // insert new number and get result

Serial.print("result: 15 = ");
Serial.println(hysteresis.add(15)); // insert new number and get result

Serial.print("result: 16 = ");
Serial.println(hysteresis.add(16)); // insert new number and get result

Serial.print("result: ");
Serial.println(hysteresis.get()); // get last result, without adding a newone


while (1);
}
5 changes: 5 additions & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Hysteresis KEYWORD1
get KEYWORD2
add KEYWORD2
set KEYWORD2
prev KEYWORD2
11 changes: 11 additions & 0 deletions library.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name=Hysteresis
author=Pavel Slama
email=Pavel Slama <[email protected]>
maintainer=Pavel Slama <[email protected]>
sentence=Hysteresis library
paragraph= (fixed point only)
url=https://github.com/pilotak/Hysteresis
includes=Hysteresis.h
category=Signal Input/Output
version=1.0.0
architectures=*

0 comments on commit ef350ac

Please sign in to comment.