Im using these component for my project and the code im using:
-Arduino UNO R3 16U2 with USB
-400 tie point interlocking solderless breadboard
-Arduino TTP223 Capacitive Touch Sensor Module ; IoT
-M to M and M to F jumper wire
byte noteON = 144;//note on command
byte note;//storage for currently playing note
int buttonPin = 7;
int potPin = A0;
boolean currentState = LOW;//stroage for current button state
boolean lastState = LOW;//storage for last button state
void setup(){
pinMode(buttonPin, INPUT);//this time we will set the pin as INPUT
Serial.begin(9600);//initialize Serial connection
}
void loop(){
currentState = digitalRead(buttonPin);
if (currentState == HIGH && lastState == LOW){//if button has just been pressed
int currentPotVal = analogRead(potPin);
note = map(currentPotVal, 0, 1023, 0, 127);
MIDImessage(noteON, note, 127);//turn note on with 127 velocity
delay(2);//crude form of button debouncing
} else if(currentState == LOW && lastState == HIGH){
MIDImessage(noteON, note, 0);//turn note off
delay(2);//crude form of button debouncing
}
lastState = currentState;
}
//send MIDI message
void MIDImessage(byte command, byte data1, byte data2) {
Serial.write(command);
Serial.write(data1);
Serial.write(data2);
}