Hi there....
Apologies for the general n00biness, only 3 days into Arduino....
I'm trying to adapt some code for a touch capacitive keyboard by Bas van Straaten, using Amanda Ghassaei's tutorials and I am having some problems. At the moment when triggered, the MIDI note will repeat until a finger is taken off. I believe the problem is within the 'if' part of the sketch, however I do not know what I should replace it with. I have tried some digital.Write commands and these are invalid.
Can anyone help?
Many thanks.
The sketch is as follows
#include <CapacitiveSensor.h>
#define cal 400
CapacitiveSensor cs_2_3 = CapacitiveSensor(2,3); // 1m Ohm capacitor
CapacitiveSensor cs_2_4 = CapacitiveSensor(2,4);
CapacitiveSensor cs_2_5 = CapacitiveSensor(2,5);
CapacitiveSensor cs_2_6 = CapacitiveSensor(2,6);
int potPin = A0;
int noteON = 144;
void setup() {
// Set MIDI baud rate:
Serial.begin(9600);
}
void loop() {
int potVal = analogRead(potPin);
byte velocity = map(potVal, 0, 1023, 0, 127);
long total1 = cs_2_3.capacitiveSensor(30);
long total2 = cs_2_4.capacitiveSensor(30);
long total3 = cs_2_5.capacitiveSensor(30);
long total4 = cs_2_6.capacitiveSensor(30);
if (total1 > cal) {
for (int note=48;note<49;note++) {//from note 50 (D3) to note 69 (A4)
MIDImessage(noteON, note, velocity);//turn note on
delay(60);
MIDImessage(noteON, note, 0);}}//turn note off
if (total2 > cal) {
for (int note=49;note<50;note++) {//from note 50 (D3) to note 69 (A4)
MIDImessage(noteON, note, velocity);//turn note on
delay(60);//hold note for 300ms
MIDImessage(noteON, note, 0);}}//turn note off
if (total3 > cal) {
for (int note=50;note<51;note++) {//from note 50 (D3) to note 69 (A4)
MIDImessage(noteON, note, velocity);//turn note on
delay(60);//hold note for 300ms
MIDImessage(noteON, note, 0);}}//turn note off
if (total4 > cal) {
for (int note=51;note<52;note++) {//from note 50 (D3) to note 69 (A4)
MIDImessage(noteON, note, velocity);//turn note on
delay(60);//hold note for 300ms
MIDImessage(noteON, note, 0);}}//turn note off
}
//send MIDI message
void MIDImessage(int command, int MIDInote, int MIDIvelocity) {
Serial.write(command);//send note on or note off command
Serial.write(MIDInote);//send pitch data
Serial.write(MIDIvelocity);//send velocity data
}