ADCTouch with midi

I kinda new, but some what expriance with arduino, but ive been trying to make a midi controller, got most of the stuff done but just one thing i need help on is that i want to implement ACDTouch to my project like when i touch the plater it send a midi command but dont know how to, if anyone can help out will be great

heres the script im using

#include <MIDI.h>
#include <RotaryEncoder.h>
#include <ADCTouch.h>

RotaryEncoder encoder(18, 19); //Encoders are connected to pins 18-19 and 2-3 (A and B of each encoder)0
RotaryEncoder encoder1(2, 3);



MIDI_CREATE_DEFAULT_INSTANCE();
int ref0, ref1;     //reference values to remove offset

int buttonApin = 12;  //footswitch A
int buttonBpin = 11;   //footswitch B
int buttonCpin = 10;   //footswitch C
int buttonDpin = 9;
int buttonEpin = 8;

int analogpot1 = A3;  //knob 1

int analogpot1Old = 0;
int analogpot1New = 0;


#define analogpot1CC 54

void setup() {
  // put your setup code here, to run once:
MIDI.begin (); // MIDI START

ref0 = ADCTouch.read(A0, 500);    //create reference values to 
ref1 = ADCTouch.read(A1, 500);

pinMode(buttonApin, INPUT_PULLUP);
pinMode(buttonBpin, INPUT_PULLUP);
pinMode(buttonCpin, INPUT_PULLUP);
pinMode(buttonDpin, INPUT_PULLUP);
pinMode(buttonEpin, INPUT_PULLUP);

pinMode(analogpot1, INPUT);

//Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:

static bool buttonAvalueOld = HIGH;
static bool buttonBvalueOld = HIGH;
static bool buttonCvalueOld = HIGH;
static bool buttonDvalueOld = HIGH;
static bool buttonEvalueOld = HIGH;

//footswitches
bool buttonAvalueNew = digitalRead(buttonApin);
bool buttonBvalueNew = digitalRead(buttonBpin);
bool buttonCvalueNew = digitalRead(buttonCpin);
bool buttonDvalueNew = digitalRead(buttonDpin);
bool buttonEvalueNew = digitalRead(buttonEpin);

    if (buttonAvalueNew != buttonAvalueOld){
      if (buttonAvalueNew == LOW){
      MIDI.sendNoteOn(60, 127, 1);
      //Serial.println("Note C On");
      }
      else {
      MIDI.sendNoteOff(60, 0, 1);
      //Serial.println("Note C Off");
      }
      buttonAvalueOld = buttonAvalueNew;
    }

      if (buttonBvalueNew != buttonBvalueOld){
      if (buttonBvalueNew == LOW){
      MIDI.sendNoteOn(64, 127, 1);
      //Serial.println("Note E On");
      }
      else {
      MIDI.sendNoteOff(64, 0, 1);
      //Serial.println("Note E Off");
      }
      buttonBvalueOld = buttonBvalueNew;
    }

      if (buttonCvalueNew != buttonCvalueOld){
      if (buttonCvalueNew == LOW){
      MIDI.sendNoteOn(65, 127, 1);
      //Serial.println("Note F On");
      }
      else {
      MIDI.sendNoteOff(65, 0, 1);
      //Serial.println("Note F Off");
      }
      buttonCvalueOld = buttonCvalueNew;
    }
    
      if (buttonDvalueNew != buttonDvalueOld){
      if (buttonDvalueNew == LOW){
      MIDI.sendNoteOn(67, 127, 1);
      //Serial.println("Note G On");
      }
      else {
      MIDI.sendNoteOff(67, 0, 1);
      //Serial.println("Note G Off");
      }
      buttonDvalueOld = buttonDvalueNew;
    }
    
      if (buttonEvalueNew != buttonEvalueOld){
      if (buttonEvalueNew == LOW){
      MIDI.sendNoteOn(69, 127, 1);
      //Serial.println("Note A On");
      }
      else {
      MIDI.sendNoteOff(69, 0, 1);
     // Serial.println("Note A Off");
      }
      buttonEvalueOld = buttonEvalueNew;
    }


//potentiometers

int pot1 = analogRead(A3);
int analogpot1New = analogRead(A3);

    if (analogpot1New - analogpot1Old >= 35 || analogpot1Old - analogpot1New >= 35) {
      analogpot1Old = analogpot1New;
      analogpot1New = (map(analogpot1New, 1023, 0, 0, 120));
      analogpot1New = (constrain(analogpot1New, 0, 120));
      MIDI.sendControlChange(analogpot1CC, analogpot1New, 1);
//      Serial.print ("pot: ");
//      Serial.println(pot1);
//      Serial.print("potread: ");
//      Serial.println(analogpot1New); 
    }
    
    static int pos = 4100;
  encoder.tick();

  int newPos = encoder.getPosition(); //Here you read the encoder position and if it has changed from the last time, you send it
  if (pos != newPos) {
    if (pos < newPos) {
      MIDI.sendControlChange(15, 1, 2);
    } else if (pos > newPos) {
      MIDI.sendControlChange(15, 127, 2);
    }
    pos = newPos;
  }
  static int pos1 = 4100;
  encoder1.tick();

  int newPos1 = encoder1.getPosition();
  if (pos1 != newPos1) {
    if (pos1 < newPos1) {
      MIDI.sendControlChange(16, 1, 2);
    } else if (pos1 > newPos1) {
      MIDI.sendControlChange(16, 127, 2);
    }
    pos1 = newPos1;
  }
   delay(25);
  }

It looks like you already copied most of the "Buttons" example that came with the ADCTouch library. You just need the part that tests the buttons:

    int value0 = ADCTouch.read(A0);   //no second parameter
    value0 -= ref0;       //remove offset
    Serial.print(value0 > 40);    //send (boolean) pressed or not pressed

Those three lines per pin can be reduced to one line per pin:

    if ((ADCTouch.read(A0) - ref0) > 40)
    {
      // Pin A0 is being touched
    }

    if ((ADCTouch.read(A1) - ref1) > 40)
    {
      // Pin A1 is being touched
    }

I got that part but how to i make that to work with midi?

The same way that you make a button work with midi.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.