Not delared in this scope.

Hi,

It's me again. :confused:

I am stuck as my Google foo has failed me this time.

Now I've pulled out so many of my hairs I'm almost bald. >:(

error: "myswitch1" was not declared in this scope.

Plus similar errors for each myswitch.

#include <MIDI.h>
#include <SoftwareSerial.h>
MIDI_CREATE_DEFAULT_INSTANCE();

void setup()
{
  for (byte i = 0; i < 5; i++)  pinMode(2 + i, INPUT); // Set pins 2 - 6 to input
  MIDI.begin(16);
}

void speed()
{
  // Set MIDI baud rate:
  Serial.begin(31250);
}

void loop()
{
  int myswitch [5];
  byte last_switch[5];

  for (byte i = 0; i < 5; i++) myswitch[i] = digitalRead(2 + i);

  if (myswitch1 != last_switch1) {
    last_switch1 = myswitch1;
    if (myswitch1 == HIGH) {
      MIDI.sendNoteOn(61, 100, 14);
      delay(100);
    } else {
      MIDI.sendNoteOff(61, 0, 14);
      delay(100);
    }
  }
  if (myswitch2 != last_switch2) {
    last_myswitch2 = myswitch2;
    if (myswitch2 == HIGH) {
      MIDI.sendNoteOn(62, 100, 14);
      delay(100);
    } else {
      MIDI.sendNoteOff(62, 0, 14);
      delay(100);
    }
  }
  if (myswitch3 != last_switch3) {
    last_switch3 = myswitch3;
    if (myswitch3 == HIGH) {
      MIDI.sendNoteOn(68, 100, 14);
      delay(100);
    } else {
      MIDI.sendNoteOff(68, 0, 14);
      delay(100);
    }
  }
  if (myswitch4 != last_switch4) {
    last_myswitch4 = myswitch4;
    if (myswitch4 == HIGH) {
      MIDI.sendNoteOn(69, 100, 14);
      delay(100);
    } else {
      MIDI.sendNoteOff(69, 0, 14);
      delay(100);
    }
  }
  if (myswitch5 != last_switch5) {
    last_myswitch5 = myswitch5;
    if (switch4 == HIGH) {
      MIDI.sendNoteOn(69, 100, 14);
      delay(100);
    } else {
      MIDI.sendNoteOff(69, 0, 14);
      delay(100);
    }
  }
}

Error report:

Midi_Footswitch_Conntroller_4:27:7: error: 'myswitch1' was not declared in this scope

if (myswitch1 != last_switch1) {

^

Midi_Footswitch_Conntroller_4:27:20: error: 'last_switch1' was not declared in this scope

if (myswitch1 != last_switch1) {

^

Midi_Footswitch_Conntroller_4:37:7: error: 'myswitch2' was not declared in this scope

if (myswitch2 != last_switch2) {

^

Midi_Footswitch_Conntroller_4:37:20: error: 'last_switch2' was not declared in this scope

if (myswitch2 != last_switch2) {

^

Midi_Footswitch_Conntroller_4:38:5: error: 'last_myswitch2' was not declared in this scope

last_myswitch2 = myswitch2;

^

Midi_Footswitch_Conntroller_4:47:7: error: 'myswitch3' was not declared in this scope

if (myswitch3 != last_switch3) {

^

Midi_Footswitch_Conntroller_4:47:20: error: 'last_switch3' was not declared in this scope

if (myswitch3 != last_switch3) {

^

Midi_Footswitch_Conntroller_4:57:7: error: 'myswitch4' was not declared in this scope

if (myswitch4 != last_switch4) {

^

Midi_Footswitch_Conntroller_4:57:20: error: 'last_switch4' was not declared in this scope

if (myswitch4 != last_switch4) {

^

Midi_Footswitch_Conntroller_4:58:5: error: 'last_myswitch4' was not declared in this scope

last_myswitch4 = myswitch4;

^

Midi_Footswitch_Conntroller_4:67:7: error: 'myswitch5' was not declared in this scope

if (myswitch5 != last_switch5) {

^

Midi_Footswitch_Conntroller_4:67:20: error: 'last_switch5' was not declared in this scope

if (myswitch5 != last_switch5) {

^

Midi_Footswitch_Conntroller_4:68:5: error: 'last_myswitch5' was not declared in this scope

last_myswitch5 = myswitch5;

^

Midi_Footswitch_Conntroller_4:69:9: error: 'switch4' was not declared in this scope

if (switch4 == HIGH) {

^

Using library MIDI_Library at version 4.3.1 in folder: C:\Users\oem\Documents\Arduino\libraries\MIDI_Library
Using library SoftwareSerial at version 1.0 in folder: C:\Program Files (x86)\arduino-1.8.9\hardware\arduino\avr\libraries\SoftwareSerial
exit status 1
'myswitch1' was not declared in this scope

Thanks for any help,

Martin

if (myswitch1 != last_switch1) {

Did you mean

if (myswitch[1] != last_switch[1]) { // :wink:

etc.

. . .

if (myswitch5 != last_switch5) { // 5 oops

Note:
int myswitch [5]; >>>>———> myswitch[0] myswitch[1] myswitch[2] myswitch[3] myswitch[4]

Hi Larry,

Brilliant, thanks very much for that reply.

Problem solved! :slight_smile:

Martin