#include <SPI.h>
#include <CapacitiveSensor.h> #include <MIDI.h> MIDI_CREATE_DEFAULT_INSTANCE();
int c3 = 36; int d3 = 38; int e3 = 40; int g3 = 43; int a3 = 45; int c4 = 48; int d4 = 50; int e4 = 52; int g4 = 55; int a4 = 57; int c5 = 60; int d5 = 62; int e5 = 64; int g5 = 67; int a5 = 69; int c6 = 72;
const int columns = 3; const int scales = 3; int potVal = 0; const int notes[scales][columns] = { {c3, d3, e3}, {c4, d4, e4}, {c5, d5, e5} }; const int numberOfSensors = 3; const int sensorPin[numberOfSensors] = {38, 39, 40};
const int ledPin[numberOfSensors] = {22, 23, 24};
const int val = 10; // this value is best around "10". works with "multiply" // and "Threshold" to enable Polyphony! int Threshold = (0); //Threshold of triggered mp3 int Multiply = (0); //increases or decreases the overal sensitivity
CapacitiveSensor cs_2_38 = CapacitiveSensor(2, 38); CapacitiveSensor cs_2_39 = CapacitiveSensor(2, 39); CapacitiveSensor cs_2_40 = CapacitiveSensor(2, 40);
void setup() { Serial.begin(9600);//midi(31250) for (int i = 0; i < numberOfSensors; i++) { pinMode(ledPin[i], OUTPUT); } } void loop() { int potVal = map(analogRead(A2), 0, 1024, 0, 3); for (int i = 0; i < numberOfSensors; i++) { checkSensor(potVal,i); } } void checkSensor(int scaleIndex, int columnIndex) { static boolean lastSensorHit1 = false; static boolean lastSensorHit2 = false; static boolean lastSensorHit3 = false;
bool sensorHit1 = cs_2_38.capacitiveSensor(Multiply) / val > (Threshold); bool sensorHit2 = cs_2_39.capacitiveSensor(Multiply) / val > (Threshold); bool sensorHit3 = cs_2_40.capacitiveSensor(Multiply) / val > (Threshold);
Multiply = map(analogRead(A0), 0, 1023, 150, 5); Threshold = map(analogRead(A1), 0, 1023, 150, 5);
if (sensorHit1 != lastSensorHit1)
if (sensorHit1 && !lastSensorHit1)
{
digitalWrite(ledPin[0], HIGH);
MIDI.sendNoteOn(notes[scaleIndex][0], 127, 1);
MIDI.sendControlChange(64, 127, 1);
}
else {
digitalWrite(ledPin[0], LOW);
MIDI.sendNoteOff(notes[scaleIndex][0], 0, 1);
MIDI.sendControlChange(64, 0, 1);
}
if (sensorHit2 != lastSensorHit2)
if (sensorHit2 && !lastSensorHit2)
{
digitalWrite(ledPin[1], HIGH);
MIDI.sendNoteOn(notes[scaleIndex][1], 127, 1);
MIDI.sendControlChange(64, 127, 1);
}
else {
digitalWrite(ledPin[1], LOW);
MIDI.sendNoteOff(notes[scaleIndex][1], 0, 1);
MIDI.sendControlChange(64, 0, 1);
}
if (sensorHit3 != lastSensorHit3)
if (sensorHit3 && !lastSensorHit3)
{
digitalWrite(ledPin[2], HIGH);
MIDI.sendNoteOn(notes[scaleIndex][2], 127, 1);
MIDI.sendControlChange(64, 127, 1);
}
else {
digitalWrite(ledPin[2], LOW);
MIDI.sendNoteOff(notes[scaleIndex][2], 0, 1);
MIDI.sendControlChange(64, 0, 1);
}
lastSensorHit1 = sensorHit1; lastSensorHit2 = sensorHit2; lastSensorHit3 = sensorHit3;
}
#include <CapacitiveSensor.h>
#include <MIDI.h>
MIDI_CREATE_DEFAULT_INSTANCE();
int c3 = 36;
int d3 = 38;
int e3 = 40;
int g3 = 43;
int a3 = 45;
int c4 = 48;
int d4 = 50;
int e4 = 52;
int g4 = 55;
int a4 = 57;
int c5 = 60;
int d5 = 62;
int e5 = 64;
int g5 = 67;
int a5 = 69;
int c6 = 72;
const int columns = 3;
const int scales = 3;
int potVal = 0;
const int notes[scales][columns] = {
{c3, d3, e3},
{c4, d4, e4},
{c5, d5, e5}
};
const int numberOfSensors = 3;
const int sensorPin[numberOfSensors] = {38, 39, 40};
const int ledPin[numberOfSensors] = {22, 23, 24};
const int val = 10; // this value is best around "10". works with "multiply"
// and "Threshold" to enable Polyphony!
int Threshold = (0); //Threshold of triggered mp3
int Multiply = (0); //increases or decreases the overal sensitivity
CapacitiveSensor cs_2_38 = CapacitiveSensor(2, 38);
CapacitiveSensor cs_2_39 = CapacitiveSensor(2, 39);
CapacitiveSensor cs_2_40 = CapacitiveSensor(2, 40);
void setup()
{
Serial.begin(9600);//midi(31250)
for (int i = 0; i < numberOfSensors; i++) {
pinMode(ledPin[i], OUTPUT);
}
}
void loop()
{
int potVal = map(analogRead(A2), 0, 1024, 0, 3);
for (int i = 0; i < numberOfSensors; i++) {
checkSensor(potVal,i);
}
}
void checkSensor(int scaleIndex, int columnIndex)
{
static boolean lastSensorHit1 = false;
static boolean lastSensorHit2 = false;
static boolean lastSensorHit3 = false;
bool sensorHit1 = cs_2_38.capacitiveSensor(Multiply) / val > (Threshold);
bool sensorHit2 = cs_2_39.capacitiveSensor(Multiply) / val > (Threshold);
bool sensorHit3 = cs_2_40.capacitiveSensor(Multiply) / val > (Threshold);
Multiply = map(analogRead(A0), 0, 1023, 150, 5);
Threshold = map(analogRead(A1), 0, 1023, 150, 5);
if (sensorHit1 != lastSensorHit1)
if (sensorHit1 && !lastSensorHit1)
{
digitalWrite(ledPin[0], HIGH);
MIDI.sendNoteOn(notes[scaleIndex][0], 127, 1);
MIDI.sendControlChange(64, 127, 1);
}
else {
digitalWrite(ledPin[0], LOW);
MIDI.sendNoteOff(notes[scaleIndex][0], 0, 1);
MIDI.sendControlChange(64, 0, 1);
}
if (sensorHit2 != lastSensorHit2)
if (sensorHit2 && !lastSensorHit2)
{
digitalWrite(ledPin[1], HIGH);
MIDI.sendNoteOn(notes[scaleIndex][1], 127, 1);
MIDI.sendControlChange(64, 127, 1);
}
else {
digitalWrite(ledPin[1], LOW);
MIDI.sendNoteOff(notes[scaleIndex][1], 0, 1);
MIDI.sendControlChange(64, 0, 1);
}
if (sensorHit3 != lastSensorHit3)
if (sensorHit3 && !lastSensorHit3)
{
digitalWrite(ledPin[2], HIGH);
MIDI.sendNoteOn(notes[scaleIndex][2], 127, 1);
MIDI.sendControlChange(64, 127, 1);
}
else {
digitalWrite(ledPin[2], LOW);
MIDI.sendNoteOff(notes[scaleIndex][2], 0, 1);
MIDI.sendControlChange(64, 0, 1);
}
lastSensorHit1 = sensorHit1;
lastSensorHit2 = sensorHit2;
lastSensorHit3 = sensorHit3;
}````````