Hi. I have this schematics diagram of this board I am using and cannot figure out/don't know how to properly identify pins in order to define and/or use them. My code relies on the X+,Y-, X+, Y- pins and I successfully used them on a feather but they needed defining... In this schematics, are they not already defined in the lower middle picture? I tried:
#define YP 2
#define XM 3
#define YM 4
#define XP 5
and that didn't work. I also tried a few others (ie- YP 18, XM 2... ) and got some life but couldn't make out a pattern. I just know that, from what I understand, both YP and XM NEED to be digital pins while YM and XP can be defined on digital or analog pins...
named pins are not connected to any esp32 chip/board.
from connector P5 pins1-4 they go to
NS2009 ( The NS2009 is a 4-wire resistive touch screen controller with I2C Interface, includes 12-bit resolution A / D converter.)
and
XPT2048 (The XPT2046 is a 4-wire resistive touch screen controller with SPI Interface that incorporates a 12-bit 125 kHz sampling SAR type. A/D converter.)
So what does that mean in relation to my code? I have never dealt with this complex seeming of a board. How do I talk to the NS2009 or XPT2048/I am using the named pins in my code... Do I just declare them or something?
// #include <MIDI.h>
#include <WiFi.h>
#include <WiFiClient.h>
#include <WiFiUdp.h>
#define SerialMon Serial
#include <AppleMIDI_Debug.h>
#include <AppleMIDI.h>
#include <stdint.h>
#include "TouchScreen.h"
// MIDI_CREATE_INSTANCE(HardwareSerial, Serial, midiInterface); // Declare the midiInterface
char ssid[] = "HOME-115"; // your network SSID (name)
char pass[] = "lucyhope"; // your network password (use for WPA, or use as key for WEP)
const int DEBOUNCE_DELAY = 50; // the debounce time; increase if the output flickers
// #define YP 33
// #define XM 32
// #define YM 22
// #define XP 23
#define YP 34
#define XM 33
#define YM 4
#define XP 5
// #define YP 18
// #define XM 19
// #define YM 4
// #define XP 5
// Initialize the touch screen
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);
// more variables
// -----------------------------------------------------------------------------
unsigned long lastDebounceTime = 0; // the last time the output pin was toggled
unsigned long t0 = millis();
int8_t isConnected = 0;
int touchMemory = false;
APPLEMIDI_CREATE_DEFAULTSESSION_INSTANCE();
void setup() {
Serial.begin(115200);
DBG_SETUP(115200);
DBG("Booting");
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
DBG("Establishing connection to WiFi..");
}
DBG("Connected to network");
DBG(F("OK, now make sure you an rtpMIDI session that is Enabled"));
DBG(F("Add device named Arduino with Host"), WiFi.localIP(), "Port", AppleMIDI.getPort(), "(Name", AppleMIDI.getName(), ")");
DBG(F("Select and then press the Connect button"));
DBG(F("Then open a MIDI listener and monitor incoming notes"));
DBG(F("Listen to incoming MIDI commands"));
MIDI.begin();
AppleMIDI.setHandleConnected([](const APPLEMIDI_NAMESPACE::ssrc_t & ssrc, const char* name) {
isConnected++;
DBG(F("Connected to session"), ssrc, name);
});
AppleMIDI.setHandleDisconnected([](const APPLEMIDI_NAMESPACE::ssrc_t & ssrc) {
isConnected--;
DBG(F("Disconnected"), ssrc);
});
}
void loop() {
MIDI.read();
// A point object holds x, y, and z (pressure) coordinates
TSPoint p = ts.getPoint();
// Translate the x and y values to MIDI range (0-127)
int midiX = map(p.x, -3072, 0, 0, 127);
int midiY = map(p.y, 0, 1023, 0, 127);
byte touchStatus;
if (p.x > -3072 && p.x < 0 && p.y > 0 && p.y < 1023) {
touchStatus = 127;
} else {
touchStatus = 0;
}
byte channel = 6; // MIDI channel (0 is Channel 1 in MIDI terms)
byte ccX = 10; // Continuous Controller number for X
byte ccY = 11; // Continuous Controller number for Y
byte ccTouchStatus = 12; // Continuous Controller number for touch status
if (touchStatus == 127) {
Serial.print("X = "); Serial.print(midiX);
MIDI.sendControlChange(ccX, midiX, channel);
Serial.print("\tY = "); Serial.println(midiY);
MIDI.sendControlChange(ccY, midiY, channel);
Serial.println(touchStatus);
MIDI.sendControlChange(ccTouchStatus, touchStatus, channel);
touchMemory = true;
} else if (touchStatus == 0 && touchMemory == true ) {
// add anything that should shut off later
Serial.println(touchStatus);
MIDI.sendControlChange(ccTouchStatus, touchStatus, channel);
touchMemory = false;
}
delay(100);
}