Code Monkey home page Code Monkey logo

inputprocessor's Introduction

For working with Arduino Inputs to provide easier, faster access to standard data processing and calibration routines

This is originally put together by A. Quitmeyer from Comingle.io 2015 - Public Domain with additional hacking on some open source simple examples by Julian Vidal https://github.com/poisa/Calibrator and Rob Tillaart

here's an example showing how to use with a regular arduino example that just reads from an analog input pin

/*
 Basic Read Analog Input from a Pin Example
 */

#include <InputProcessor.h>

InputProcessor in0(30, A2); // setup the input processor to have 30 samples, and read from analog pin 2

// the setup routine runs once when you press reset:
void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);

  // calibrate for 3 seconds
  in0.calibrate(3000);
}

// the loop routine runs over and over again forever:
void loop() {

  //getting your values that are already scaled and calibrated is this easy
  int  mycalibratedvalue = in0.update();

  //getting a value that is smoothed by the rolling average, and calibrated is also easy!
  int mycalibratedandsmoothedvalue = in0.getscaledAverage();

}

it gets even more interesting though when you feed it an arbitrary function! It really opens up your possibilities! (your arbitrary function can even be the output of a different input processor to go into different levels of processing!

/*
Read and process input from an arbitrary function
 */

#include <InputProcessor.h>

// setup the input processor to have 30 samples
InputProcessor in0(30);  // note there is no second argument because that would be for a pin


void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);

  // calibrate for 3 seconds
  in0.calibrate(3000, myarbitraryfunction);  //feed it a second argument pointing to this value you have
  //doesn't make as much sense with a static value, but could depend on your use case, or maybe you wouldn't want to calibrate
}

//your arbitrary function needs to return an int!
int myarbitraryfunction(){
  
//Doig some custom processing with inputs
return analogRead(A0)+analogRead(A1);

}

// the loop routine runs over and over again forever:
void loop() {

  //getting your values that are already scaled and calibrated is this easy
  int  mycalibratedvalue = in0.update(myarbitraryfunction);

  //getting a value that is smoothed by the rolling average, and calibrated is also easy!
  int mycalibratedandsmoothedvalue = in0.getscaledAverage();

  //for demo reasons this will list a lot of the other values you can get
  inputSerialMessages();

}

void inputSerialMessages() {

  Serial.print (in0.rawValue);
  Serial.print(", scale ");
  Serial.print (in0.scaledValue);
  Serial.print(", buffavg ");
  Serial.print (in0.getAverage());
  Serial.print(", buffavgscaled ");
  Serial.print (in0.getscaledAverage());
  Serial.print(", sum ");
  Serial.print (in0.getBuffSum());

  Serial.print(", avgdiff ");
  Serial.print (in0.getAvgDiff());


  Serial.print(", custom offset ");
  Serial.print (in0.offset);
  Serial.print(", offsetavgdiff ");
  Serial.print (constrain(in0.getoffsetAvgDiff() * 5, 0, 255));

  Serial.print(", calmin ");
  Serial.print (in0.min);
  Serial.print(", calMax ");
  Serial.println (in0.max);

  Serial.print(", STDEV ");
  Serial.print (in0.getSTDEV());
}

inputprocessor's People

Contributors

quitmeyer avatar

Watchers

James Cloos avatar Martin FHIR ADT avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.