Need help with multiple LED modes

I need help sorting out my code to flash LEDs in multiple modes. I have my flash patterns all figured out and working properly. Its the mode selection side of things Im having issues with. I found an example of some code I thought would fit my needs and coppied it into my sketch. When I try to compile I get "exit status 1 mode 2 was not declared it this scope" what puzzles me is how did it make it past mode 3 when they are exactly the same?

#define RELAY1  53

#define RELAY2  52

#define RELAY3  51

#define RELAY4  50

#define RELAY5  49

#define RELAY6  48

#define RELAY7  47

#define RELAY8  46

#define RELAY9  45

#define RELAY10  44

#define RELAY11  43

#define RELAY12  42

#define RELAY13  41

#define RELAY14  40

#define RELAY15  39

#define RELAY16  38

boolean button[] = {2, 3, 4}; //pin assignment for buttons

boolean buttonstate = 0;
int mode = 0;

void setup()
{
  pinMode(RELAY1, OUTPUT);

  pinMode(RELAY2, OUTPUT);

  pinMode(RELAY3, OUTPUT);

  pinMode(RELAY4, OUTPUT);

  pinMode(RELAY5, OUTPUT);

  pinMode(RELAY6, OUTPUT);

  pinMode(RELAY7, OUTPUT);

  pinMode(RELAY8, OUTPUT);

  pinMode(RELAY9, OUTPUT);

  pinMode(RELAY10, OUTPUT);

  pinMode(RELAY11, OUTPUT);

  pinMode(RELAY12, OUTPUT);

  pinMode(RELAY13, OUTPUT);

  pinMode(RELAY14, OUTPUT);

  pinMode(RELAY15, OUTPUT);

  pinMode(RELAY16, OUTPUT);

  for (int x = 0; x < 3; x++) //starts a loop to set the pin modes for all button pins
  {
    pinMode(button[x], INPUT);
  }
  for (int x = 0; x < 3; x++) //starts a loop to set the buttons to a default of HIGH
  {
    pinMode(button[x], HIGH);
  }

}

void loop()
{ 
  buttoncheck(); //calls to the void buttoncheck() section for checking the buttons
  
  if (mode == 1)
  {
    mode1(); //directs the program to the section with the flashes you selected
  }
  if (mode == 2) 
  {                           //////////////ERROR OCCURS HERE
    mode2(); //directs the program to the section with the flashes you selected
  }
  if (mode == 3)
  {
    mode3(); //directs the program to the section with the flashes you selected
  }

}

void buttoncheck()
{
  for (int x = 0; x < 5; x++) //loop for checking all the buttons
  {
    buttonstate = digitalRead(button[x]);
    if (buttonstate == LOW && button[x] == 2) //number equals the button the pin is connected too
    {
      mode = 1; // number equals the mode you want to run
    }
    if (buttonstate == LOW && button[x] == 3)
    {
      mode = 2;
    }
    if (buttonstate == LOW && button[x] == 4)
    {
      mode = 3;
    }

  }
}


void mode1()
/////////LEDs flash in pattern 1,  code omited for space


void mode2()
////////////LEDs flash in pattern 2, code omited for space

void mode3()
/////////LEDs flash in pattern 3, code omited for space

?

void mode1()
LEDs flash in pattern 1

void mode2()
LEDs flash in pattern 2

void mode3()
LEDs flash in pattern 3

Be consistent about the switch count

boolean button[] = {2, 3, 4}; //pin assignment for buttons
. . .

for (int x = 0; x < 5; x++) //loop for checking all the buttons

.

You have no functions mode1 mode2 mode3.

I'm a little surprised the compiler didn't complain about the bare text, too

I removed the functions in mode1,mode2, mode3 to shorten the code for posting. That has all been tested separately and works just fine. I went back and clarified in the code.

Please, you must show us your complete sketch. Attach your code using the </> icon on the left side of the posting menu.
Put your sketch between the code tags

[code]Paste your sketch here[/code]

rngr2000:
I removed the functions in mode1,mode2, mode3 to shorten the code for posting. That has all been tested separately and works just fine.

OK, thanks for wasting my time.

I'd like to wish you good luck.
But I can't be arsed.

LarryD:
?

void mode1()
LEDs flash in pattern 1

void mode2()
LEDs flash in pattern 2

void mode3()
LEDs flash in pattern 3

Be consistent about the switch count

boolean button[] = {2, 3, 4}; //pin assignment for buttons
. . .

for (int x = 0; x < 5; x++) //loop for checking all the buttons

.

I fixed that. The original sketch had 5 modes, mine only has 3. I missed that when I copied and pasted it.

AWOL:
OK, thanks for wasting my time.

I'd like to wish you good luck.
But I can't be arsed.

'Id love to post it, but it is really long. It puts me over the 9000 character limit.

rngr2000:
I removed the functions in mode1,mode2, mode3 to shorten the code for posting. That has all been tested separately and works just fine. I went back and clarified in the code.

Putting // in front of your "LED flash...." and adding brackets for your functions, it compiles without error for me. I guess your bugs are in the missing code after all. :wink:

LarryD:
Please, you must show us your complete sketch. Attach your code using the </> icon on the left side of the posting menu.
Put your sketch between the code tags

[code]Paste your sketch here[/code]

It wont let me, its too long. I can maybe email it to you?

rngr2000:
It wont let me, its too long. I can maybe email it to you?

Split in two posts!

Click Reply and use the "Attachments and other options" button, browse to your file and Attach it.

rngr2000:
It wont let me, its too long. I can maybe email it to you?

Or you could attach it.

And/or you could ask "why did I let my code grow this big before fixing this basic problem?"

The compiler doesn't find all the errors, it stops when it finds one. The order that it finds it in isn't just top to bottom.
And when it points out 'where' an error is, it could be because an error elsewhere is causing the error, so it's not always specifically "something is wrong right here"

Ok. Thanks for the help. This is, hopefully, the complete code. I know the notes don't match the relay numbers. As I was writing the code I used the copy and paste and didn't go back and edit all of those notes.

_3_mode_sketch_test.ino (58.7 KB)

It looks to me like you've got code that isn't in any function.

Double line spacing doesn't help, neither does the erratic indentation.

AWOL:
Or you could attach it.

And/or you could ask "why did I let my code grow this big before fixing this basic problem?"

It got so long because I wrote mode1 first. I then added the other two "simple" modes. I then started to learn how to switch between the 3 of them. That is when I ran into problems.

delay(50);
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
buttoncheck;

Hmm.

No wonder code grown huge. 50+ of these lines, and it is just wrong.

} //turns relay 16 on

...and plenty of these, what are they supposed to do?

delay(0);

This is more or less the same. No extra line spacing , delay was mostly 0 between digitalWrite LOW and 5 between digitalWrite HIGH but it was not consistent. Now it is easy to see pattern in relays. Compiled size went from 14,8 to 3,2 kB

#define RELAY1  53
#define RELAY2  52
#define RELAY3  51
#define RELAY4  50
#define RELAY5  49
#define RELAY6  48
#define RELAY7  47
#define RELAY8  46
#define RELAY9  45
#define RELAY10  44
#define RELAY11  43
#define RELAY12  42
#define RELAY13  41
#define RELAY14  40
#define RELAY15  39
#define RELAY16  38
boolean button[] = {2, 3, 4}; //pin assignment for buttons
boolean buttonstate = 0;
int mode = 0;

void setup() {
  pinMode(RELAY1, OUTPUT);
  pinMode(RELAY2, OUTPUT);
  pinMode(RELAY3, OUTPUT);
  pinMode(RELAY4, OUTPUT);
  pinMode(RELAY5, OUTPUT);
  pinMode(RELAY6, OUTPUT);
  pinMode(RELAY7, OUTPUT);
  pinMode(RELAY8, OUTPUT);
  pinMode(RELAY9, OUTPUT);
  pinMode(RELAY10, OUTPUT);
  pinMode(RELAY11, OUTPUT);
  pinMode(RELAY12, OUTPUT);
  pinMode(RELAY13, OUTPUT);
  pinMode(RELAY14, OUTPUT);
  pinMode(RELAY15, OUTPUT);
  pinMode(RELAY16, OUTPUT);
  for (int x = 0; x < 3; x++) { //starts a loop to set the pin modes for all button pins
    pinMode(button[x], INPUT);
  }
  for (int x = 0; x < 3; x++) {//starts a loop to set the buttons to a default of HIGH
    pinMode(button[x], HIGH);
  }
}

void loop() {
  buttoncheck(); //calls to the void buttoncheck() section for checking the buttons
  if (mode == 1)  {
    mode1(); //directs the program to the section with the flashes you selected
  }
  if (mode == 2)  {
    mode2(); //directs the program to the section with the flashes you selected
  }
  if (mode == 3)  {
    mode3(); //directs the program to the section with the flashes you selected
  }
}

void buttoncheck() {
  for (int x = 0; x < 3; x++) { //loop for checking all the buttons
    buttonstate = digitalRead(button[x]);
    if (buttonstate == LOW && button[x] == 2) { //number equals the button the pin is connected too
      mode = 1; // number equals the mode you want to run
    }
    if (buttonstate == LOW && button[x] == 3) {
      mode = 2;
    }
    if (buttonstate == LOW && button[x] == 4) {
      mode = 3;
    }
  }
}

void relayPattern(int a, int b, int c, int d, int e, int f, int g, int h) {
  digitalWrite (RELAY1, a);
  digitalWrite (RELAY16, a);
  if (b) delay(5);
  digitalWrite (RELAY2, b);
  digitalWrite (RELAY15, b);
  if (c) delay(5);
  digitalWrite (RELAY3, c);
  digitalWrite (RELAY14, c);
  if (d) delay(5);
  digitalWrite (RELAY4, d);
  digitalWrite (RELAY13, d);
  if (e) delay(5);
  digitalWrite (RELAY5, e);
  digitalWrite (RELAY12, e);
  if (f) delay(5);
  digitalWrite (RELAY6, f);
  digitalWrite (RELAY11, f);
  if (g) delay(5);
  digitalWrite (RELAY7, g);
  digitalWrite (RELAY10, g);
  if (h) delay(5);
  digitalWrite (RELAY8, h);
  digitalWrite (RELAY9, h);

}

void mode1() {
  for (int i = 0; i <= 3; i++) { //first pattern repeat 4 times)
    relayPattern(0, 0, 0, 1, 1, 1, 1, 1);
    delay(25);
    relayPattern(1, 0, 0, 0, 1, 1, 1, 1);
    delay(25);
    relayPattern(1, 1, 0, 0, 0, 1, 1, 1);
    delay(25);
    relayPattern(1, 1, 1, 0, 0, 0, 1, 1);
    delay(25);
    relayPattern(1, 1, 1, 1, 0, 0, 0, 1);
    delay(25);
    relayPattern(1, 1, 1, 1, 1, 0, 0, 0);
    delay(25);
    relayPattern(0, 1, 1, 1, 1, 1, 0, 0);
    delay(25);
    relayPattern(0, 0, 1, 1, 1, 1, 1, 0);
    delay(25);
    relayPattern(0, 0, 0, 1, 1, 1, 1, 1); //remove this line for more fluid motion as this is
              // same as start pattern. This will be on for double time as it is now
    delay(25); //--------------------------end of first cycle
  }
  buttoncheck();
  relayPattern(0, 0, 0, 1, 1, 1, 1, 1);
  delay(50);
  relayPattern(1, 1, 1, 1, 1, 1, 1, 1);
  delay(50);
  relayPattern(0, 0, 0, 1, 1, 1, 1, 1);
  delay(50);
  relayPattern(1, 1, 1, 1, 1, 1, 1, 1);
  delay(50);
  buttoncheck();
  relayPattern(1, 0, 0, 0, 1, 1, 1, 1);
  delay(50);
  relayPattern(1, 1, 1, 1, 1, 1, 1, 1);
  delay(50);
  relayPattern(1, 0, 0, 0, 1, 1, 1, 1);
  delay(50);
  relayPattern(1, 1, 1, 1, 1, 1, 1, 1);
  delay(50);
  buttoncheck();
  relayPattern(1, 1, 0, 0, 0, 1, 1, 1);
  delay(50);
  relayPattern(1, 1, 1, 1, 1, 1, 1, 1);
  delay(50);
  relayPattern(1, 1, 0, 0, 0, 1, 1, 1);
  delay(50);
  relayPattern(1, 1, 1, 1, 1, 1, 1, 1);
  delay(50);
  buttoncheck();
  relayPattern(1, 1, 1, 0, 0, 0, 1, 1);
  delay(50);
  relayPattern(1, 1, 1, 1, 1, 1, 1, 1);
  delay(50);
  relayPattern(1, 1, 1, 0, 0, 0, 1, 1);
  delay(50);
  relayPattern(1, 1, 1, 1, 1, 1, 1, 1);
  delay(50);
  buttoncheck();
  relayPattern(1, 1, 1, 1, 0, 0, 0, 1);
  delay(50);
  relayPattern(1, 1, 1, 1, 1, 1, 1, 1);
  delay(50);
  relayPattern(1, 1, 1, 1, 0, 0, 0, 1);
  delay(50);
  relayPattern(1, 1, 1, 1, 1, 1, 1, 1);
  delay(50);
  buttoncheck();
  relayPattern(1, 1, 1, 1, 1, 0, 0, 0);
  delay(50);
  relayPattern(1, 1, 1, 1, 1, 1, 1, 1);
  delay(50);
  relayPattern(1, 1, 1, 1, 1, 0, 0, 0);
  delay(50);
  relayPattern(1, 1, 1, 1, 1, 1, 1, 1);
  delay(50);
}

void mode2() {
  //flash your LEDs how you want in here for this mode
  //a call to buttoncheck can be added in anywhere you want
  //so that the program can continue to check for a button
  //press even while it's in the middle of the mode.
  //When a button is pressed it stores what mode it needs to
  //go to next and will move to that mode once the sequence is over.
  buttoncheck();
  digitalWrite (RELAY1, HIGH);
  digitalWrite (RELAY16, HIGH);
  digitalWrite (RELAY3, HIGH);
  digitalWrite (RELAY14, HIGH);
  digitalWrite (RELAY5, HIGH);
  digitalWrite (RELAY12, HIGH);
  digitalWrite (RELAY7, HIGH);
  digitalWrite (RELAY10, HIGH);
}

void mode3() {
  //flash your LEDs how you want in here for this mode
  //a call to buttoncheck can be added in anywhere you want
  //so that the program can continue to check for a button
  //press even while it's in the middle of the mode.
  //When a button is pressed it stores what mode it needs to
  //go to next and will move to that mode once the sequence is over.
  buttoncheck();
  digitalWrite (RELAY1, LOW);
  digitalWrite (RELAY16, LOW);
  digitalWrite (RELAY2, LOW);
  digitalWrite (RELAY15, LOW);
  digitalWrite (RELAY3, LOW);
  digitalWrite (RELAY14, LOW);
  digitalWrite (RELAY4, LOW);
  digitalWrite (RELAY13, LOW);
  digitalWrite (RELAY5, LOW);
  digitalWrite (RELAY12, LOW);
  digitalWrite (RELAY6, LOW);
  digitalWrite (RELAY11, LOW);
  digitalWrite (RELAY7, LOW);
  digitalWrite (RELAY10, LOW);
  digitalWrite (RELAY8, LOW);
  digitalWrite (RELAY9, LOW);
}