Need a little help with coding error

Hello. Im trying to figure out what is wrong with the below code. Spend the last hour looking and no luck.

#include <TimerOne.h>
#include <Bounce2.h>
#include <Keyboard.h>

//I have used pin 10 on my board for my switch
const int inputPin = 10;

Bounce button0 = Bounce();
Bounce button1 = Bounce();
Bounce button2 = Bounce();
Bounce button3 = Bounce();
Bounce button4 = Bounce();
Bounce button5 = Bounce();

Bounce button[6] = {
  Bounce(),
  Bounce(),
  Bounce(),
  Bounce(),
  Bounce(),
  Bounce()
};

//debounce milliseconds
const int debounce = 5;
//Switch Pins
const byte k[4] = { 4, 5, 6, 7 };
//Switch status
boolean s[4] = { 0, 0, 0, 0 };


byte col = 0;
byte leds[2][2];
const int keyfade = 40;
const char curve[]  =
{
  0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 5, 5, 6, 6, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 7, 7, 6, 6, 5, 5, 4, 4, 3, 3, 2, 2, 1, 1, 1
};
const int fadecount = 2;
const unsigned long breathcount = 5000;
int fadecounter = 0;
unsigned long breathcounter = 0;
byte pass = 1;


// pin[xx] on led matrix connected to nn on Arduino (-1 is dummy to make array start at pos 1)
int pins[6] =
{
  -1, 18, 19, 20, 21
};


// col[xx] of leds = pin yy on led matrix
int cols[2] =
{
  pins[2], pins[1]
};


// row[xx] of leds = pin yy on led matrix
int rows[2] =
{
  pins[4], pins[3]
};






void setup()
{
  setupLeds();
  onLeds();
  //setup inputs, turn on pullups
  for (int i = 0; i < 4; i++)
  {
    pinMode(k[i], INPUT);
    digitalWrite(k[i], 1);
  }
  {
  // Sets up the input pin for your single switch
  button0.attach(inputPin);

  for (int i = 4; i <= 9; i++) {
    pinMode(13 - i, INPUT_PULLUP);
    digitalWrite(13 - i, HIGH);
    button[i - 4].attach(13 - i);
  }
  //starts the keyboard emulator
  Keyboard.begin();
}
}


void loop()
{
  CheckKeys();
  delay(debounce);


  fadecounter++;
  if (fadecounter > fadecount)
  {
    fadecounter = 0;
    fade();
  }
  breathcounter++;
  if (breathcounter > breathcount)
  {
    breathcounter = 0;
    fadecounter = 0;
    breath();
  }
 {
  // put your main code here, to run repeatedly:

  button[2].update();
  if (button[2].fallingEdge()) {


    //Locks computer
    Keyboard.press(KEY_LEFT_GUI);
    Keyboard.press('l');
    Keyboard.releaseAll();
  }
  button[3].update();
  if (button[3].fallingEdge()) {

    //CSC main pass
    Keyboard.print("gganev2");
    delay (500);
    Keyboard.press(KEY_TAB);
    Keyboard.print("Far.cot-18");
    delay (500); 
    Keyboard.press(KEY_RETURN);
    Keyboard.releaseAll();
    
  }
  button[4].update();
  if (button[4].fallingEdge()) {

    //Unlock
    Keyboard.print("Far.cot-18");
    
    Keyboard.releaseAll();
  }
  button[5].update();
  if (button[5].fallingEdge()) {

    //HPIM Incident
    Keyboard.print("I will check this one.");
    Keyboard.press(KEY_RETURN);
    Keyboard.releaseAll();

    delay(500);

  }
 
}


void CheckKeys()
{
  for (int i = 0; i < 4; i++)
  {
    if (digitalRead(k[i]) == 0)
    {
      if (s[i] == 0)
      {
        s[i] = 1;
        byte row = i / 2;
        byte col = i % 2;
        leds[col][row] = 60;
        breathcounter = 0;
      }
    }
    else
    {
      if (s[i] == 1)
      {
        s[i] = 0;
        byte row = i / 2;
        byte col = i % 2;
        leds[col][row] = 60;
        breathcounter = 0;
      }
    }
  }
}


void setupLeds()
{
  // sets the pins as output
  for (int i = 1; i <= 4; i++)
  {
    pinMode(pins[i], OUTPUT);
  }


  // set up cols and rows
  for (int i = 1; i <= 2; i++)
  {
    digitalWrite(cols[i - 1], HIGH);
  }


  for (int i = 1; i <= 2; i++)
  {
    digitalWrite(rows[i - 1], LOW);
  }


  clearLeds();


  // Set refresh rate (interrupt timeout period)
  Timer1.initialize(500);
  // Set interrupt routine to be called
  Timer1.attachInterrupt(display);
}


void clearLeds()
{
  // Clear display array
  for (int i = 0; i < 2; i++)
  {
    for (int j = 0; j < 2; j++)
    {
      leds[i][j] = 0;
    }
  }
}


void onLeds()
{
  for (int i = 0; i < 2; i++)
  {
    for (int j = 0; j < 2; j++)
    {
      leds[i][j] = keyfade;
    }
  }
}


void fade()
{
  for (int i = 0; i < 2; i++)
  {
    for (int j = 0; j < 2; j++)
    {
      if (leds[i][j] > 0)
      {
        leds[i][j] = leds[i][j] - 1;
      }
    }
  }
}


void breath()
{
  for (int i = 0; i < 2; i++)
  {
    for (int j = 0; j < 2; j++)
    {
      leds[i][j] = 60;
    }
  }
}


// Interrupt routine
void display()
{
  digitalWrite(cols[col], HIGH);  // Turn whole previous column off
  col++;
  if (col == 2)
  {
    col = 0;
    pass++;
    if (pass > 8)
    {
      pass = 1;
    }
  }
  for (int row = 0; row < 2; row++)
  {
    if (curve[leds[col][row]] > pass)
    {
      digitalWrite(rows[row], HIGH);  // Turn on this led
    }
    else
    {
      digitalWrite(rows[row], LOW); // Turn off this led
    }
  }
  digitalWrite(cols[col], LOW); // Turn whole column on at once (for equal lighting times)
}

Error states that: setupLeds' was not declared in this scope

Thank you in advance for the help

Do an auto format (ctrl-t or Tools, Auto Format) on the code and you will see that the curly bracket (}) to close the loop() function is missing.

Thanks for this, but after auto format I receive this one:

Arduino: 1.8.9 (Windows 10), Board: "Arduino Leonardo"

C:\Users\gganev2\Desktop\sketch_mar27a\sketch_mar27a.ino: In function 'void setup()':

sketch_mar27a:73:13: error: 'setupLeds' was not declared in this scope

   setupLeds();

             ^

sketch_mar27a:74:10: error: 'onLeds' was not declared in this scope

   onLeds();

          ^

C:\Users\gganev2\Desktop\sketch_mar27a\sketch_mar27a.ino: In function 'void loop()':

sketch_mar27a:98:13: error: 'CheckKeys' was not declared in this scope

   CheckKeys();

             ^

sketch_mar27a:106:10: error: 'fade' was not declared in this scope

     fade();

          ^

sketch_mar27a:113:12: error: 'breath' was not declared in this scope

     breath();

            ^

C:\Users\gganev2\Desktop\sketch_mar27a\sketch_mar27a.ino: At global scope:

sketch_mar27a:119:1: error: 'button' does not name a type

 button[2].update();

 ^

sketch_mar27a:120:1: error: expected unqualified-id before 'if'

 if (button[2].fallingEdge()) {

 ^

sketch_mar27a:128:1: error: 'button' does not name a type

 button[3].update();

 ^

sketch_mar27a:129:1: error: expected unqualified-id before 'if'

 if (button[3].fallingEdge()) {

 ^

sketch_mar27a:141:1: error: 'button' does not name a type

 button[4].update();

 ^

sketch_mar27a:142:1: error: expected unqualified-id before 'if'

 if (button[4].fallingEdge()) {

 ^

sketch_mar27a:149:1: error: 'button' does not name a type

 button[5].update();

 ^

sketch_mar27a:150:1: error: expected unqualified-id before 'if'

 if (button[5].fallingEdge()) {

 ^

sketch_mar27a:161:1: error: expected declaration before '}' token

 }

 ^

Multiple libraries were found for "Keyboard.h"
 Used: C:\Program Files (x86)\Arduino\libraries\Keyboard
 Not used: C:\Users\gganev2\Documents\Arduino\libraries\Keyboard-1.0.2
exit status 1
'setupLeds' was not declared in this scope

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Did you add the missing curly bracket?

         //HPIM Incident
         Keyboard.print("I will check this one.");
         Keyboard.press(KEY_RETURN);
         Keyboard.releaseAll();

         delay(500);

      }

   }
}  // added

Thanks for this, but after auto format I receive this one:

Auto Format does not fix problems but it tidies up code and helps show problems with layout.

Where is the end of the loop() function ?

To expand on what UKHeliBob said. Here is the portion of your code after auto format (before being fixed). Note how void CheckKeys() is indented. That means that the IDE thinks that void CheckKeys() is part of the loop() function.

        delay(500);
      }
   }

   void CheckKeys()
   {
      for (int i = 0; i < 4; i++)

The same portion of code after adding the missing }. Note that void CheckKeys() is no longer indented? That means that the void CheckKeys() is now a function on its own outside of loop().

        delay(500);
      }
   }
} // added

void CheckKeys()
{
   for (int i = 0; i < 4; i++)

As advised I have added the missing curly bracket and:

C:\Users\gganev2\Desktop\sketch_mar27a\sketch_mar27a.ino: In function 'void setup()':

sketch_mar27a:73:13: error: 'setupLeds' was not declared in this scope

   setupLeds();

             ^

sketch_mar27a:74:10: error: 'onLeds' was not declared in this scope

   onLeds();

          ^

C:\Users\gganev2\Desktop\sketch_mar27a\sketch_mar27a.ino: In function 'void loop()':

sketch_mar27a:99:13: error: 'CheckKeys' was not declared in this scope

   CheckKeys();

             ^

sketch_mar27a:107:10: error: 'fade' was not declared in this scope

     fade();

          ^

sketch_mar27a:114:12: error: 'breath' was not declared in this scope

     breath();

            ^

C:\Users\gganev2\Desktop\sketch_mar27a\sketch_mar27a.ino: At global scope:

sketch_mar27a:162:1: error: expected declaration before '}' token

 }

 ^

Multiple libraries were found for "Keyboard.h"
 Used: C:\Program Files (x86)\Arduino\libraries\Keyboard
 Not used: C:\Users\gganev2\Documents\Arduino\libraries\Keyboard-1.0.2
exit status 1
'setupLeds' was not declared in this scope

This is a combination of two codes, and trying to merge them in one working and....

Post the modified code. We can't help with code that we cannot see. I added the curly bracket and the code compiles for me (IDE 1.8.5, Leonardo).

All done. Stupid me put the reverse bracket. Thank you very much for the prompt help :slight_smile: