Arduino Script

#include <Wire.h>

#include <String.h>

#include "Adafruit_MPR121.h"

  

Adafruit_MPR121 cap = Adafruit_MPR121();

  

const int buttonPin = 6;

  

String gestures[] = {

"Top_Left_Quadrant_Touch",

"Top_Right_Quadrant_Touch",

"Bottom_Left_Quadrant_Touch",

"Bottom_Right_Quadrant_Touch",

"Center_Touch"

};

  

int gestureIndex = 0;

bool isGestureBeingPerformed = false;

  

void setup() {

Serial.begin(19200);

  

while (!Serial) {

delay(10);

}

Serial.println("Adafruit MPR121 Capacitive Touch sensor test");

  

if (!cap.begin(0x5A)) {

Serial.println("MPR121 not found, check wiring?");

while (1);

}

Serial.println("MPR121 found!");

pinMode(buttonPin, INPUT_PULLUP);

}

  

void loop() {

// Check button state

if (digitalRead(buttonPin) == LOW) {

isGestureBeingPerformed = true;

} else if (isGestureBeingPerformed) {

isGestureBeingPerformed = false;

gestureIndex = (gestureIndex + 1) % 5; // to the next gesture when the button is released

}

  

String dataString = "";

  

for (uint8_t j = 0; j < 12; j++) {

int baseline = cap.baselineData(j);

int filtered = cap.filteredData(j);

int delta = filtered - baseline;

  

dataString += "[" + String(baseline) + "," + String(filtered) + "," + String(delta) + "]";

if (j < 11) {

dataString += " ";

}

}

  

// Append the gesture to dataString

if (isGestureBeingPerformed) {

dataString += " Gesture: " + gestures[gestureIndex];

} else {

dataString += " Gesture: No Gesture";

}

Serial.println(dataString);

delay(5);

}