Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
383c608
Add c++ to js compilation and static react site
dxinteractive Jun 3, 2018
2ae27eb
Update readme with a todo
dxinteractive Jun 3, 2018
645fb05
Fix circle ci cache settings
dxinteractive Jun 3, 2018
14df35f
Fix circle ci yaml again
dxinteractive Jun 3, 2018
377edfa
Include emscripten in circle cahce
dxinteractive Jun 3, 2018
8790cb8
Move into docs directory
dxinteractive Jun 3, 2018
c1d4c4e
...
dxinteractive Jun 3, 2018
435f048
...
dxinteractive Jun 3, 2018
6c1b8ac
Remove tutorial code
dxinteractive Jun 3, 2018
a958f53
Attemt to retain path changes by running emcc install and excution in…
dxinteractive Jun 3, 2018
6693141
Make env vars
dxinteractive Jun 3, 2018
480a654
Make env vars
dxinteractive Jun 3, 2018
17a5ddf
Node 10
dxinteractive Jun 3, 2018
8b3ee04
use blueflag image
dxinteractive Jun 3, 2018
edc688c
Add dcme style
dxinteractive Jun 3, 2018
86985a2
Try stretch
dxinteractive Jun 4, 2018
b4d5891
Add path prefix
dxinteractive Jun 4, 2018
3df500b
Delete public files
dxinteractive Jun 4, 2018
74e4142
Gitignore public files
dxinteractive Jun 4, 2018
387be86
Dodgily ask for pathprefixed jslib.js and not
dxinteractive Jun 4, 2018
1866533
Test some stuff
dxinteractive Jun 4, 2018
b741974
Bundle wasm
dxinteractive Jun 5, 2018
f8c1e6b
Bump styles
dxinteractive Jun 5, 2018
0d48d58
Restructure docs files
dxinteractive Jun 9, 2018
1423a1f
Sketch out API and stub Arduino.h
dxinteractive Jun 9, 2018
fb55c5d
Reminder
dxinteractive Jun 9, 2018
5e7e506
Basic simulation harness going (js > c++ > js)
dxinteractive Jun 10, 2018
360af3a
Minor style tweaks
dxinteractive Jun 24, 2018
ebf641c
Add graph
dxinteractive Jun 30, 2018
ea890fd
Add controls
dxinteractive Jul 1, 2018
9fc153b
Begin demo docs
dxinteractive Jul 7, 2018
d5abe6c
Start meking demo components
dxinteractive Jul 7, 2018
00f049b
Add line chart
dxinteractive Jul 8, 2018
ada4423
Add sliders
dxinteractive Jul 8, 2018
582a3ee
Min, max, zoom
dxinteractive Jul 9, 2018
8764ead
Add code settings
dxinteractive Jul 10, 2018
04a26ff
Split out api files
dxinteractive Jul 12, 2018
c373a57
Allow code component to have modifiers for colour schemes
dxinteractive Jul 12, 2018
09c1d89
Allow structure to receive elements as props
dxinteractive Jul 12, 2018
d0facfd
Render demo code
dxinteractive Jul 12, 2018
03ba32e
Add noise and noisefloor controls
dxinteractive Jul 12, 2018
786b5a9
Add divider style
dxinteractive Jul 12, 2018
2e43504
Temporarily disable graph
dxinteractive Jul 12, 2018
c43d211
Improve simulation noise, update sim settings
dxinteractive Jul 12, 2018
76c0ebe
Add ability to have exponentional sliders
dxinteractive Jul 12, 2018
1845e39
Flesh out ResponsiveAnalogRead, bring in parts of old algorithm
dxinteractive Jul 12, 2018
8026430
Add glide, remove quick
dxinteractive Jul 13, 2018
d0ef3c8
Add code settings sliders, add glide
dxinteractive Jul 13, 2018
e7afc1e
Improve chart speed
dxinteractive Jul 13, 2018
1721145
Tinkering with the algorithm
dxinteractive Jul 13, 2018
c95cd1e
Update docs
dxinteractive Jul 13, 2018
59455e1
Update styles
dxinteractive Jul 14, 2018
9321ce4
Trying out another algorithm
dxinteractive Jul 17, 2018
610680c
More tweaking
dxinteractive Jul 18, 2018
0bf1460
wip
dxinteractive Jun 9, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
version: 2
jobs:
build:
working_directory: ~/responsive-analog-read
docker:
- image: circleci/node:10-stretch

steps:
- checkout
- restore_cache:
keys:
- v1-dependencies-{{ checksum "docs/yarn.lock" }}
- v1-dependencies-
- run: cd docs && yarn && yarn install-emcc
- save_cache:
paths:
- docs/node_modules
- docs/emsdk-portable.tar.gz
- docs/emsdk-portable
key: v1-dependencies-{{ checksum "docs/yarn.lock" }}

- deploy:
command: |
if [ "${CIRCLE_BRANCH}" == "master" ] || [ "${CIRCLE_BRANCH}" == "release/version-2" ]; then
git config --global -l && git config --global user.email circleci@circleci && git config --global user.name CircleCI && cd docs && yarn deploy
fi

15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# http://editorconfig.org
root = true

[*]
indent_style = space
indent_size = 4
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false

[*.{yml,json}]
indent_size = 2
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Project dependencies
.cache
node_modules

# site / gatsby
/docs/public

# emscripten
/docs/emsdk-portable
/docs/emsdk-portable.tar.gz*

# misc
*.log.*
*.log
.DS_Store
159 changes: 3 additions & 156 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,168 +1,15 @@
# ResponsiveAnalogRead
![ResponsiveAnalogRead](http://damienclarke.me/content/1-code/3-responsive-analog-read/thumbnail.jpg)

ResponsiveAnalogRead is an Arduino library for eliminating noise in analogRead inputs without decreasing responsiveness. It sets out to achieve the following:
TODO - make that image par of the docs build

1. Be able to reduce large amounts of noise when reading a signal. So if a voltage is unchanging aside from noise, the values returned should never change due to noise alone.
2. Be extremely responsive (i.e. not sluggish) when the voltage changes quickly.
3. Have the option to be responsive when a voltage *stops* changing - when enabled the values returned must stop changing almost immediately after. When this option is enabled, a very small sacrifice in accuracy is permitted.
4. The returned values must avoid 'jumping' up several numbers at once, especially when the input signal changes very slowly. It's better to transition smoothly as long as that smooth transition is short.

You can preview the way the algorithm works with [sleep enabled](http://codepen.io/dxinteractive/pen/zBEbpP) (minimising the time spend transitioning between values) and with [sleep disabled](http://codepen.io/dxinteractive/pen/ezdJxL) (transitioning responsively and accurately but smooth).

An article discussing the design of the algorithm can be found [here](http://damienclarke.me/code/posts/writing-a-better-noise-reducing-analogread).

## How to use

Here's a basic example:

```Arduino
// include the ResponsiveAnalogRead library
#include <ResponsiveAnalogRead.h>

// define the pin you want to use
const int ANALOG_PIN = A0;

// make a ResponsiveAnalogRead object, pass in the pin, and either true or false depending on if you want sleep enabled
// enabling sleep will cause values to take less time to stop changing and potentially stop changing more abruptly,
// where as disabling sleep will cause values to ease into their correct position smoothly and with slightly greater accuracy
ResponsiveAnalogRead analog(ANALOG_PIN, true);

// the next optional argument is snapMultiplier, which is set to 0.01 by default
// you can pass it a value from 0 to 1 that controls the amount of easing
// increase this to lessen the amount of easing (such as 0.1) and make the responsive values more responsive
// but doing so may cause more noise to seep through if sleep is not enabled

void setup() {
// begin serial so we can see analog read values through the serial monitor
Serial.begin(9600);
}

void loop() {
// update the ResponsiveAnalogRead object every loop
analog.update();

Serial.print(analog.getRawValue());
Serial.print("\t");
Serial.print(analog.getValue());

// if the responsive value has change, print out 'changed'
if(analog.hasChanged()) {
Serial.print("\tchanged");
}

Serial.println("");
delay(20);
}
```

### Using your own ADC

```Arduino
#include <ResponsiveAnalogRead.h>

ResponsiveAnalogRead analog(0, true);

void setup() {
// begin serial so we can see analog read values through the serial monitor
Serial.begin(9600);
}

void loop() {
// read from your ADC
// update the ResponsiveAnalogRead object every loop
int reading = YourADCReadMethod();
analog.update(reading);
Serial.print(analog.getValue());

Serial.println("");
delay(20);
}
```

### Smoothing multiple inputs

```Arduino
#include <ResponsiveAnalogRead.h>

ResponsiveAnalogRead analogOne(A1, true);
ResponsiveAnalogRead analogTwo(A2, true);

void setup() {
// begin serial so we can see analog read values through the serial monitor
Serial.begin(9600);
}

void loop() {
// update the ResponsiveAnalogRead objects every loop
analogOne.update();
analogTwo.update();

Serial.print(analogOne.getValue());
Serial.print(analogTwo.getValue());

Serial.println("");
delay(20);
}
```

## How to install

In the Arduino IDE, go to Sketch > Include libraries > Manage libraries, and search for ResponsiveAnalogRead.
You can also just use the files directly from the src folder.

Look at the example in the examples folder for an idea on how to use it in your own projects.
The source files are also heavily commented, so check those out if you want fine control of the library's behaviour.

## Constructor arguments

- `pin` - int, the pin to read (e.g. A0).
- `sleepEnable` - boolean, sets whether sleep is enabled. Defaults to true. Enabling sleep will cause values to take less time to stop changing and potentially stop changing more abruptly, where as disabling sleep will cause values to ease into their correct position smoothly.
- `snapMultiplier` - float, a value from 0 to 1 that controls the amount of easing. Defaults to 0.01. Increase this to lessen the amount of easing (such as 0.1) and make the responsive values more responsive, but doing so may cause more noise to seep through if sleep is not enabled.

## Basic methods

- `int getValue() // get the responsive value from last update`
- `int getRawValue() // get the raw analogRead() value from last update`
- `bool hasChanged() // returns true if the responsive value has changed during the last update`
- `void update(); // updates the value by performing an analogRead() and calculating a responsive value based off it`
- `void update(int rawValue); // updates the value by accepting a raw value and calculating a responsive value based off it (version 1.1.0+)`
- `bool isSleeping() // returns true if the algorithm is in sleep mode (version 1.1.0+)`

## Other methods (settings)

### Sleep

- `void enableSleep()`
- `void disableSleep()`

Sleep allows you to minimise the amount of responsive value changes over time. Increasingly small changes in the output value to be ignored, so instead of having the responsiveValue slide into position over a couple of seconds, it stops when it's "close enough". It's enabled by default. Here's a summary of how it works:

1. "Sleep" is when the output value decides to ignore increasingly small changes.
2. When it sleeps, it is less likely to start moving again, but a large enough nudge will wake it up and begin responding as normal.
3. It classifies changes in the input voltage as being "active" or not. A lack of activity tells it to sleep.

### Activity threshold
- `void setActivityThreshold(float newThreshold) // the amount of movement that must take place for it to register as activity and start moving the output value. Defaults to 4.0. (version 1.1+)`

### Snap multiplier
- `void setSnapMultiplier(float newMultiplier)`

SnapMultiplier is a value from 0 to 1 that controls the amount of easing. Increase this to lessen the amount of easing (such as 0.1) and make the responsive values more responsive, but doing so may cause more noise to seep through when sleep is not enabled.

### Edge snapping
- `void enableEdgeSnap() // edge snap ensures that values at the edges of the spectrum (0 and 1023) can be easily reached when sleep is enabled`

### Analog resolution
- `void setAnalogResolution(int resolution)`

If your ADC is something other than 10bit (1024), set that using this.
Something something version 2.

## License

Licensed under the MIT License (MIT)

Copyright (c) 2016, Damien Clarke
Copyright (c) 2018, Damien Clarke

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Expand Down
7 changes: 7 additions & 0 deletions docs/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"plugins": [
["prismjs", {
"languages": ["cpp"]
}]
]
}
15 changes: 15 additions & 0 deletions docs/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# http://editorconfig.org
root = true

[*]
indent_style = space
indent_size = 4
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false

[*.{yml,json}]
indent_size = 2
4 changes: 4 additions & 0 deletions docs/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
**/*-test.js
**/gastby-node.js
**/parcels-docs
**/node_modules
10 changes: 10 additions & 0 deletions docs/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": [
"eslint-config-blueflag",
"eslint-config-blueflag/react",
"eslint-config-blueflag/flow"
],
"rules": {
"newline-per-chained-call": "off"
}
}
7 changes: 7 additions & 0 deletions docs/gatsby-browser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* Implement Gatsby's Browser APIs in this file.
*
* See: https://www.gatsbyjs.org/docs/browser-apis/
*/

// You can delete this file if you're not using it
19 changes: 19 additions & 0 deletions docs/gatsby-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// @flow
module.exports = {
pathPrefix: '/ResponsiveAnalogRead',
siteMetadata: {
title: 'ResponsiveAnalogRead'
},
plugins: [
'gatsby-plugin-sass',
'gatsby-plugin-react-helmet',
{
resolve: 'gatsby-transformer-remark',
options: {
plugins: [
`gatsby-remark-prismjs`
]
}
}
]
};
19 changes: 19 additions & 0 deletions docs/gatsby-node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Implement Gatsby's Node APIs in this file.
*
* See: https://www.gatsbyjs.org/docs/node-apis/
*/

exports.modifyWebpackConfig = ({config}) => {
return config
.loader("wasm", {
test: /\.wasm$/,
loaders: ['buffer-loader']
})
.merge({
node: {
fs: 'empty',
child_process: 'empty'
}
});
};
7 changes: 7 additions & 0 deletions docs/gatsby-ssr.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* Implement Gatsby's SSR (Server Side Rendering) APIs in this file.
*
* See: https://www.gatsbyjs.org/docs/ssr-apis/
*/

// You can delete this file if you're not using it
44 changes: 44 additions & 0 deletions docs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"name": "responsive-analog-read-site",
"private": true,
"description": "responsive-analog-read-site",
"version": "0.0.0",
"author": "Damien Clarke <dxinteractive@gmail.com>",
"dependencies": {
"babel-plugin-prismjs": "^1.0.2",
"blueflag-test": "^0.18.1",
"bruce": "^5.0.0",
"buffer-loader": "^0.0.1",
"chart.js": "^2.7.2",
"dcme-style": "^0.12.1",
"gatsby": "^1.9.247",
"gatsby-link": "^1.6.40",
"gatsby-plugin-react-helmet": "^2.0.10",
"gatsby-plugin-sass": "^1.0.26",
"gatsby-remark-prismjs": "^1.2.21",
"gatsby-transformer-remark": "^1.7.34",
"gh-pages": "^1.1.0",
"goose-css": "^0.12.0",
"mdx-loader": "^1.1.0",
"mdxc": "^1.1.1",
"numeral": "^2.0.6",
"parcels-react": "^0.12.0",
"prismjs": "^1.15.0",
"rc-slider": "^8.6.1",
"react-animation-frame": "^1.0.1",
"react-chartjs-2": "^2.7.2",
"react-helmet": "^5.2.0",
"stampy": "^0.39.0",
"unmutable": "^0.29.2"
},
"scripts": {
"build-gatsby": "gatsby build",
"build": "yarn wasm-build && gatsby build",
"deploy": "yarn wasm-build && gatsby build --prefix-paths && gh-pages -d public",
"watch": "yarn wasm-build && gatsby develop",
"test": "echo \"Error: no test specified\" && exit 1",
"install-emcc": "./wasm/install-emcc.sh",
"path-emcc": "./wasm/path-emcc.sh",
"wasm-build": "./wasm/build.sh"
}
}
16 changes: 16 additions & 0 deletions docs/src/api/ApiView.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// @flow
import React from 'react';
import Code from '../component/Code';
import {Box, Message, Text} from 'dcme-style';

export default () => <Box>
<Text element="h2" modifier="sizeGiga marginGiga">API</Text>
<Text element="h3" modifier="sizeMega marginMega">.pin()</Text>
<Box modifier="marginBottomKilo">
<Code>void pin(int pin);</Code>
</Box>
<Text element="p" modifier="margin">Sets the analog input pin that will be read.</Text>
<Box modifier="marginRowKilo">
<Message>You don't need to set this if you will be using your own ADC or passing in your own values to <Text modifier="weightKilo">.read()</Text></Message>
</Box>
</Box>;
Loading