Hi, coders! I know enough to be dangerous, but not enough to nail my first code project for Teensy 4.0. I probably won't be coding again in the near future, so learning everything from scratch doesn't make sense for me. If I could get some help fixing and finishing this code, I would greatly appreciate it. Here's the project: I'm using 8 Sharp GP2Y0A02YK0F Infrared Proximity Sensors as a MIDI instrument. To start, I just want to program one sensor to send a MIDI note via USB MIDI. If it's fast enough, I'll add the other 7. The idea is, when I put my hand over a sensor, the voltage changes and sends the MIDI note (from there I'll patch the MIDI signal to my software synth for actual sound).

Here is the code I've cobbled together. I'm sure I'm missing some definitions or initializations. The error I'm currently getting is "usbMIDI was not declared within this scope". Please give this a look and tell me what I'm obviously doing wrong. TIA

int noteIsOn;

void setup() {


void loop() {

  if (noteIsOn == false) {
    if (analogRead(0) > 200) {
      usbMIDI.sendNoteOn(60, 100, 1);
      noteIsOn = true;
  } else {
    if (analogRead(0) < 200) {
      usbMIDI.sendNoteOff (60, 0, 1);
      noteIsOn = false;
  while (usbMIDI.read()) {}