#include <M5Stack.h>
#include <driver/dac.h> //Arduino-ESP32 driver
#include <MIDI.h>
MIDI_CREATE_INSTANCE(HardwareSerial, Serial2, MIDI);
#define AMAX 100
int tm[AMAX];
byte nt[AMAX];
int pt = 0;
int trans = 0;
void handleNoteOn(byte channel, byte pitch, byte velocity)
{
MIDI.sendNoteOn(pitch + trans, velocity, 1);
char disp[100];
sprintf(disp, "Ch:%02x %02x %02x", channel, pitch, velocity);
M5.Lcd.setCursor(10, 50);
M5.Lcd.printf(disp);
}
void handleNoteOff(byte channel, byte pitch, byte velocity)
{
MIDI.sendNoteOff(pitch + trans, 0, 1);
}
void setup()
{
M5.begin();
dacWrite(25, 0); // Speaker OFF
dac_output_disable( DAC_CHANNEL_1 );
MIDI.setHandleNoteOn(handleNoteOn);
MIDI.setHandleNoteOff(handleNoteOff);
MIDI.begin(MIDI_CHANNEL_OMNI);
MIDI.turnThruOff();
M5.Lcd.setTextSize(2);
M5.Lcd.setCursor(0, 0);
M5.Lcd.print("MIDI IN -> Trans -> OUT");
memset(tm, 0, sizeof(tm));
memset(nt, 0, sizeof(nt));
}
void loop()
{
M5.update();
if(M5.BtnA.wasPressed()){
trans --;
}
if(M5.BtnC.wasPressed()){
trans ++;
}
char disp[100];
sprintf(disp, "T:%02d", trans);
M5.Lcd.setCursor(10, 80);
M5.Lcd.printf(disp);
MIDI.read();
printf("%d\n", pt);
}