#include <Plaquette.h>
#include <CapacitiveSensor.h>
#include <PqOsc.h>
//STEP ONE: attach your probe to the object you wish to convert into a capacitive button
//STEP TWO: turn on the Arduino and open the serial monitor
//argument 1: pin that sends electrical signal
//argument 2: pin that senses change
CapacitiveSensor capSensor = CapacitiveSensor(7, 8);
// place a 1M resistor between these two pins, and a jumper cable with one end connected to the pin that senses change
//OSC SLIP node (128 byte buffer, 115200 baud)
OscSlip<128> oscSlip(115200);
long sensorValue; // a long is just a super mega big integer
bool wasTouched = false; // variable that is 0 or 1
MinMaxScaler myMinMax(30);
Metronome sensorMetro(0.1);
DigitalOut led(5);
Smoother mySmooth(0.1);
//Monitor monitor(9600);
OscIn maxStartStop(oscSlip, "/arduinoStartStop"); // IMPORTANT! MaxMSP - microcontroller handshake for establishing clean signal
OscOut oscOutSensor(oscSlip, "/clem1", 'f');
//OscOut oscOutButton2(oscSlip, "/bouton2");
// threshold for capacitive sensing event
float threshold = 0.7;
void step() {
if (maxStartStop) {
//the sensor is always gathering data
sensorValue = capSensor.capacitiveSensor(50); // returns the average of every x measurements
//print(sensorValue);
//print(" ");
sensorValue >> mySmooth >> myMinMax;
myMinMax >> oscOutSensor;
//println(myMinMax);
if (!wasTouched && myMinMax > threshold) {
1.0 >> oscOutSensor;
//do an event once
//println("~~~~~touch");
wasTouched = true; // rappel: true == 1 == HIGH == 5v
led.on();
}
if (myMinMax <= threshold) {
// println("..");
wasTouched = false; //rappel: false == 0 == LOW == GND
led.off();
}
}
}This is just a bare wire...that becomes your "touch sensor."
Connect this wire to any object you want to turn into a touch sensor.