Skip to content

Instantly share code, notes, and snippets.

@sabas1080
Last active April 2, 2019 19:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sabas1080/da819325b7ed61a9c52459dc6f4860e4 to your computer and use it in GitHub Desktop.
Save sabas1080/da819325b7ed61a9c52459dc6f4860e4 to your computer and use it in GitHub Desktop.
This example demonstrates how to use Meow Meow with MIDI USB
/************************************************************
meowmeow_midiusb.ino
Meow Meow - Using the Meow Meow you can make anything into a key
just by connecting a few alligator clips
Andres Sabas @ Electronic Cats
Original Creation Date: April 2, 2019
https://github.com/ElectronicCats/MeowMeow
This example demonstrates how to use Meow Meow with MIDI USB
Development environment specifics:
IDE: Arduino 1.8.4
Hardware Platform:
Meow Meow
- SAMD21G18
This code is beerware; if you see me (or any other Electronic Cats
member) at the local, and you've found our code helpful,
please buy us a round!
Distributed as-is; no warranty is given.
*/
#include "MIDIUSB.h"
#include "Adafruit_FreeTouch.h"
bool leftButtonPressed;
bool rightButtonPressed;
bool noteOneOn;
bool noteTwoOn;
int CALIBRATION = 50; // Change this variable to something between your capacitive touch serial readouts for on and off
long oldState = 0;
long touch_init0,touch_init1,touch_init2;
Adafruit_FreeTouch qt_0 = Adafruit_FreeTouch(A0, OVERSAMPLE_4, RESISTOR_50K, FREQ_MODE_NONE); // S
Adafruit_FreeTouch qt_1 = Adafruit_FreeTouch(A1, OVERSAMPLE_4, RESISTOR_50K, FREQ_MODE_NONE); // D
Adafruit_FreeTouch qt_2 = Adafruit_FreeTouch(A2, OVERSAMPLE_4, RESISTOR_50K, FREQ_MODE_NONE); // Arrow LEFT
void setup() {
//Serial.begin(115200);
//while (!Serial);
if (! qt_0.begin())
Serial.println(F("Failed to begin qt on pin A0"));
if (! qt_1.begin())
Serial.println(F("Failed to begin qt on pin A1"));
if (! qt_2.begin())
Serial.println(F("Failed to begin qt on pin A2"));
touch_init0 = qt_0.measure();
touch_init1 = qt_1.measure();
touch_init2 = qt_2.measure();
}
void loop() {
// make the new measurement
long newState0 = qt_0.measure();
long newState1 = qt_1.measure();
leftButtonPressed = ((abs(newState0 - touch_init0) > CALIBRATION) ? 1 : 0);
rightButtonPressed = ((abs(newState1 - touch_init1) > CALIBRATION) ? 1 : 0);
//Serial.println(leftButtonPressed);
//Serial.println(rightButtonPressed);
//Control note one based on left button
if (leftButtonPressed && !noteOneOn) {
noteOn(0, 60, 100);
noteOneOn = true;
}
else if (!leftButtonPressed && noteOneOn) {
noteOff(0, 60, 100);
noteOneOn = false;
}
//Control note two based on right button
if (rightButtonPressed && !noteTwoOn) {
noteOn(0, 64, 100);
noteTwoOn = true;
}
else if (!rightButtonPressed && noteTwoOn){
noteOff(0, 64, 100);
noteTwoOn = false;
}
//Use light sensor as a modulation control
/*int value = qt_2.measure(); //value from 0-1024
value = value/8; //scale to 0-127 for MIDI CC
controlChange(0, 1, value); //send as MIDI modulation control
*/
delay(20);
}
void noteOn(byte channel, byte pitch, byte velocity) {
midiEventPacket_t noteOn = {0x09, 0x90 | channel, pitch, velocity};
MidiUSB.sendMIDI(noteOn);
}
void noteOff(byte channel, byte pitch, byte velocity) {
midiEventPacket_t noteOff = {0x08, 0x80 | channel, pitch, velocity};
MidiUSB.sendMIDI(noteOff);
}
void controlChange(byte channel, byte control, byte value) {
midiEventPacket_t event = {0x0B, 0xB0 | channel, control, value};
MidiUSB.sendMIDI(event);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment