Skip to content

Instantly share code, notes, and snippets.

@unknowndomain
Created May 2, 2017 17:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save unknowndomain/9d7122a5beb44b5b3ebf6c8a4928fdfd to your computer and use it in GitHub Desktop.
Save unknowndomain/9d7122a5beb44b5b3ebf6c8a4928fdfd to your computer and use it in GitHub Desktop.
Demos how to use the https://github.com/BareConductive/mpr121 library to get touch values and proximity values from each electrode.
#include <MPR121.h>
#include <Wire.h>
#define numElectrodes 12
void setup() {
Serial.begin( 9600 );
Wire.begin();
// Setup MPR121
MPR121.begin( 0x5A );
MPR121.setInterruptPin( 4 );
MPR121.setTouchThreshold( 40 );
MPR121.setReleaseThreshold( 20 );
}
void loop() {
// Check for new data
MPR121.updateTouchData();
MPR121.updateFilteredData();
// Get an analog proximity value
Serial.print( MPR121.getFilteredData( 1 ) );
// Get a touched/not touched value
if ( MPR121.getTouchData( 1 ) ) {
Serial.println( " - Touching" );
} else {
Serial.println( " - Not Touching" );
}
}
@42droid
Copy link

42droid commented Feb 6, 2018

Lovely example 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment