This Library is designed to make the integration of 'Flex Sensors' easier and simpler. The Idea of this Library is to create a built in way to smooth out data, register 'bent' actions, as well as create an easy way of tracking individual Sensors.
Author: Tyler Gragg
This repo was first created to provide an easier way to read, calibrate, and implement flex sensors in a project. This repo provides the abliity to smooth out data as in comes in from the Flex Sensor using a few different smoothing algoithms. I first used this in a 3D printed robotic hand:
Here's a tutorial that SparkFun made on how to use the sensors:
Latest documentation is kept in the wiki page here:
The Flex() class has the following data members:
- int sensorPin - The analog pin the Flex sensor is read into
- int minInput - Min Input on the flex sensors themselves - this is used for calibration on the sensors
- int maxInput - Max Input on the flex sensors themselves - this is used for calibration on the sensors
- int numReadings - The number of reading you want to take into the Averaging / Smoothing Process
- int readIndex - Where we are in the averaging process
- int smoothingType - Options are: NONE, AVG, RUN_AVG, EXP
- int weight - Weight for the Exponential smoothing process only. Has no effect on other smoothing algorithms.
- int* vals - An array to hold the previous Values
- int* expVals - Used for the exponential smoothing function
I have overloaded the constructor so that you can do anything from super quick and easy implementation to defining all the parameters of your Flex Sensor in one go.
For any constructor that does not define all the data members, the following are set as the default:
minInput = 400
maxInput = 700
numReadings = 10
smoothingType = NONE
weight = 0
Flex(int SensorPin, int minInput, int maxInput)
Flex(int SensorPin, int numReadings, int smoothingType, int weight)
Flex(int SensorPin, int minInput, int maxInput, int numReadings, int smoothingType)
Flex(int SensorPin, int minInput, int maxInput, int numReadings, int smoothingType, int weight)
Get and Set
You have the ability to get or set the following data members:
void setSensorPin(int sensorPin)
Returns the most recent value from the sensor.
Returns the min value from a calibrated FlexSensor
Returns the max value from a calibrated FlexSensor
void setMaxInput(int maxInput)
void setMinInput(int minInput)
void setMinMaxInput(int minInput, int maxInput)
Updates the sensor once, then replaces minInput or maxInput if that sensor reading was smaller or larger respectively. Designed to be used in a loop multiple times, see example.
Updates the current reading of the sensor. Should be somewhere in your main loop().
Returns true if the current sensor value is greater than 60% bent, otherwise false.