I got this to totally work. Here is my code. Now I am going to hopefully utilize the HX8357D Adafruit 3.5 TFT screen I am using to add some interesting graphic content. Hopefully it is as easy as it looks in the video product promo video 3.5 graphic tutorial page I'm referring to... but here's my code for a MIDI Screen that, for me, will turn on an effect, let me manipulate its parameters while touching the screen, then turn of as I let go:
// #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[] = "ATT4K"; // your network SSID (name)
char pass[] = "[secret]"; // 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
// 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);
}
Any hints on making my next step easier would be awesome. I have heard I might need to go into a header file of the HX8357D library and enable my screen?!?! We shall see.. but this works great for x/y touch and took a while to find pins that would work and also weren't ones that I wanted/need to use later.