Errors in my code...HELP! (32 note organ pedalboard using Arduino Mega)

I am a cellist and organist and I am trying to convert a 32-note organ pedal board to MIDI for practice at home. I am using the book “MIDI and ARDUINO: organ bass pedal encoders” by Tom Scarff. I plan to use an ARDUINO Mega 2560 and a MIDI board. I don’t know anything about entering or programming code. I haven’t bought the ARDUINO board, so it is not connected to my laptop yet. I hope this time I correctly followed the rules of this forum. After entering the whole program and verifying I get the following error messages:


C:\Users\macon\OneDrive\Documents\Arduino\Arduino12345678\Arduino12345678.ino: In function 'void loop()':
C:\Users\macon\OneDrive\Documents\Arduino\Arduino12345678\Arduino12345678.ino:103:7: error: 'noteOff' was not declared in this scope
noteOff(MIDIchannel, note, velocity);
^~~~~~~
C:\Users\macon\OneDrive\Documents\Arduino\Arduino12345678\Arduino12345678.ino:103:7: note: suggested alternative: 'noteff'
noteOff(MIDIchannel, note, velocity);
^~~~~~~
noteff

exit status 1

Compilation error: 'noteOff' was not declared in this scope


Here is my code:


#include <MIDI.h>

//PROGRAM: A design with an 32 switch encoder circuit, to produce Bass pedal outputs,
//with Octave UP/DOWN switches.

//variables setup
int octave = 0;
int midiByte;
byte MIDIchannel = 2;  // midi channel 3
byte channel;
byte x;
byte LedPin = 13;  // select the pin for the LED
byte count;
byte note;
byte velocity = 100;
byte currentSwitch = 0;
int startNote = 36;

//32 bass switches + octave and Channel up + octave down switches = 36 switch inputs-
byte switches[36] = {
  22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 8, 9, 10, 11
};

byte switchState[36] = {
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};

//---------------------------------------------

void setup() {


  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  //GND 0 Volt supply to opto-coupler
  digitalWrite(3, LOW);
  // +5 Volt supply to opto-coupler
  digitalWrite(2, HIGH);

  //Set Inputs for 4 way DIP Switch
  pinMode(4, INPUT_PULLUP);
  pinMode(5, INPUT_PULLUP);
  pinMode(6, INPUT_PULLUP);
  pinMode(7, INPUT_PULLUP);


  //Set Inputs for Octave up/down Switches
  pinMode(8, INPUT_PULLUP);
  pinMode(9, INPUT_PULLUP);
  //Set Inputs for Channel up/down Switches
  pinMode(10, INPUT_PULLUP);
  pinMode(11, INPUT_PULLUP);

  //pins 22 to 53 corresponding to switches 1 to 32
  for (x = 22; x < 54; x++) {
    pinMode(x, INPUT);
    digitalWrite(x, HIGH);
  }

  //declare the LED's pin as output
  pinMode(LedPin, OUTPUT);

  for (x = 1; x <= 4; x++) {
    digitalWrite(LedPin, HIGH);
    delay(300);
    digitalWrite(LedPin, LOW);
    delay(300);
  }

  //start serial with midi baudrate 31250
  Serial.begin(31250);
  Serial.flush();
}
//----------------------------------------
void loop() {

  //Read 4-Way DIP switch
  MIDIchannel = digitalRead(4) + (digitalRead(5) << 1) + (digitalRead(6) << 2) + (digitalRead(7 << 3));
  MIDIchannel + MIDIchannel + 1;

#include <MIDI.h>
  MIDI_CREATE_DEFAULT_INSTANCE();

  MIDI.begin(MIDI_CHANNEL_OMNI);

  //scan 32 switches on inputs
  for (int n = 0; n < 32; n++) {
    currentSwitch = digitalRead(switches[n]);

    //switch pressed and NOT pressed previously
    if (currentSwitch == LOW && switchState[n] == LOW) {

      switchState[n] = HIGH;
      note = n;
      noteOn(MIDIchannel, note, velocity);
    }

    // switch released AND pressed previosly
    if (currentSwitch == HIGH && switchState[n] == HIGH) {
      switchState[n] = LOW;
      note = n;
      noteOff(MIDIchannel, note, velocity);
    }
  }
  //-----------------------------------

  //scan 2 Octave and Channel switches on inputs
  for (int n = 32; n < 36; n++) {
    currentSwitch = digitalRead(switches[n]);

    // switch pressed and NOT pressed previosly
    if (currentSwitch == LOW && switchState[n] == LOW) {
      //---------------------------------------------------
      if (n == 32) {
        octave = octave + 12;
        if (octave >= 12) {
          octave = 12;
        }
      }
      //----------------------
      if (n == 33) {
        octave = octave - 12;
        if (octave <= -12) {
          octave = -12;
        }
      }
      //---------------------
      if (n == 34) {
        MIDIchannel = MIDIchannel + 1;
        if (MIDIchannel >= 15) {
          MIDIchannel = 15;
        }
      }
      //-------------------------
      if (n == 35) {
        MIDIchannel = MIDIchannel - 1;
        if (MIDIchannel <= 0) {
          MIDIchannel = 0;
        }
      }
      switchState[n] = HIGH;
    }

    // switch released AND pressed previosly
    if (currentSwitch == HIGH && switchState[n] == HIGH) {

      switchState[n] = LOW;
    }
  }
  delay(20);
}

//---------------------------------

//Send a MIDI note-on message.
void noteOn(byte channel, byte note, byte velocity) {
  midiMsg((0x90 + channel), note + startNote + octave,
          velocity);
}

//Send a MIDI note-off message.
void noteff(byte channel, byte note, byte velocity) {
  midiMsg((0x80 + channel), note + startNote + octave,
          velocity);
}

//Send a general MIDI message
void midiMsg(byte cmd, byte data1, byte data2) {

  digitalWrite(LedPin, HIGH);
  Serial.write(cmd);
  Serial.write(data1);
  Serial.write(data2);
  digitalWrite(LedPin, LOW);
}
//---------------------------------------------------------------------

The compiler is quite unforgiving about spelling mistakes. However, it is equally helpful in pointing them out and suggesting what you might correct.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.