Mini Midi Sensor

Mini Midi Sensor

November 18, 2019 DIY / Maker 0

Optical distance sensor midi controller played by @angkerfoot in a conch shell with a tiny usb #arduino @sparkfun #promicro to control a filter/wah/muffle sorta thing live. no max, just straight up midi folks. it’s the same Sharp sensor from the game controller midi fella. People often compare this to a Theremin.

code for arduino pro micro (leonardo)

#include <MIDIUSB.h>
#include <Adafruit_NeoPixel.h>

// Woz Supposedly of Greasy Conversation - 7-30-18
// didn't make the button do anything yet, was going to make it change cc numbers
int space = 30;
int channel = 2; //starts with 0, so the real channel shows up as this number +1
int r = 0;
int g = 0;
int b = 0;
int j = 1;
int distchange = 0;
#define distfilter 15
#define MIDI_CC MIDI_CC_GENERAL1
Adafruit_NeoPixel strip = Adafruit_NeoPixel(1, 15, NEO_GRB + NEO_KHZ800);

void controlChange(byte thechannel, byte control, byte value) {
  midiEventPacket_t event = {0x0B, 0xB0 | thechannel, control, value};
  MidiUSB.sendMIDI(event);
  MidiUSB.flush();
}

  void pitchBendChange(byte thechannel, int value) {
  byte lowValue = value & 0x7F;
  byte highValue = value >> 7;
  midiEventPacket_t event = {0x0E, 0xE0 | thechannel, lowValue, highValue};
  MidiUSB.sendMIDI(event);
  MidiUSB.flush();
}

void setup() {
    Serial.begin(9600);      // open the serial port at 9600 bps:    

    pinMode(15, OUTPUT);  //LED pin

  pinMode(A0, INPUT);
 strip.begin();
  strip.show(); // Initialize all pixels to 'off'
   strip.setBrightness(255);
}

void loop() {

//check sensor
int distcheck = analogRead(A0);
if(distcheck<175){distcheck = 0;}
if((distcheck<distchange-distfilter)||(distcheck>distchange+distfilter)){
if(distcheck>1000){distcheck = 0;}
  int dist = ((distcheck-175)/4.25);
  if(dist>127){dist=127;}
  if(dist<0){dist=0;}
  int dr = dist*5.8;
    if(dr>255){dr=255;}
  int dg = (dist*5.8)-255;
          if(dg<0){dg=0;}
        if(dg>255){dg=255;}
  int db = (dist*5.8)-511;
          if(db>255){db=255;}
        if(db<0){db=0;}
 
  strip.setPixelColor(0, strip.Color(dr,dg,db));
 
strip.show();
controlChange(channel, space, dist); 
distchange = distcheck;
 }

 //void loop     
}