Skip to content

Instantly share code, notes, and snippets.

@Ryoga-exe
Created December 11, 2023 08:35
Show Gist options
  • Save Ryoga-exe/52911c1a0df669dca9f0575215777994 to your computer and use it in GitHub Desktop.
Save Ryoga-exe/52911c1a0df669dca9f0575215777994 to your computer and use it in GitHub Desktop.
#include <Wire.h>
#include "Adafruit_MPR121.h"
Adafruit_MPR121 cap = Adafruit_MPR121();
uint16_t currtouched = 0;
uint16_t state[12] = {};
uint16_t rstate[12] = {};
bool tstate[12] = {};
const char Data[3] = { 1, 0, -1 };
void setup() {
Serial.begin(2000000);
while (!Serial) { // needed to keep leonardo/micro from starting too fast!
delay(10);
}
if (!cap.begin(0x5A)) {
Serial.println("-1");
while (1);
}
Serial.println("0");
}
void loop() {
// currtouched = cap.touched();
for (uint8_t i=0; i<12; i++) {
if (cap.filteredData(i) < cap.baselineData(i) - 5){
state[i]++;
rstate[i] = 0;
}
else {
rstate[i]++;
state[i] = 0;
}
}
for (uint8_t i=0; i<12; i++) {
if (!tstate[i]) {
if (state[i] >= 3) {
tstate[i] = true;
}
}
else {
if (rstate[i] >= 3) {
tstate[i] = false;
}
}
}
for (uint8_t i=0; i<12; i++) {
if (tstate[i]) {
Serial.print('1');
}
else {
Serial.print('0');
}
}
Serial.print(' ');
// delay(2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment