Keypad error: was not declared in this scope

Hi everyone

I'm recently new to arduino 
I tried a project with a keyboard an 3 leds

It works with two leds but when I write the code for the third led it says: "error: scanRow was not declared in this scope"

Appreciate the help

thx,
Kobydee











[code]
int rowCounter =0; // row counter
int columnCounter =0; // column counter
int foundColumn = 0;
boolean foundCol = false;
int keyValue = 0;
int noKey = 0;
boolean readKey = false;
int debounce = 300; // set this to the lowest value that gives the best result
const int row1 = 2;
const int row2 = 3;
const int row3 = 4;
const int row4 = 5;
const int colA = 8;
const int colB = 9;
const int colC = 10;
const int colD = 11;
const int redPin = 6; // onboard LED
const int greenPin = 12;
const int yellowPin = 13;

void setup(){
Serial.begin(9600);
pinMode(row1, OUTPUT);
pinMode(row2, OUTPUT);
pinMode(row3, OUTPUT);
pinMode(row4, OUTPUT);
pinMode(colA, INPUT_PULLUP);
pinMode(colB, INPUT_PULLUP);
pinMode(colC, INPUT_PULLUP);
pinMode(colD, INPUT_PULLUP);
//
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(yellowPin, OUTPUT);
digitalWrite(redPin, LOW); // turn LED off
digitalWrite(greenPin, LOW);
digitalWrite(yellowPin, LOW);
}

void loop(){
if(noKey == 16){ // no keys were pressed
readKey = true; // keyboard is ready to accept a new keypress
}
noKey = 0;
for(rowCounter=row1; rowCounter<(row4 +1); rowCounter++){
scanRow(); // switch on one row at a time
for(columnCounter = colA; columnCounter <colD +1; columnCounter++){
readColumn(); // read the switch pressed
if (foundCol== true){
keyValue =(rowCounter-row1) +4*(columnCounter - colA);



if(readKey==true && noKey == 15){ // a key has been pressed
Serial.println(keyValue); // used for debug
if (keyValue == 13){
digitalWrite(redPin, !digitalRead(redPin)); // toggles LED ON/OFF

else{
digitalWrite(redPin, LOW);
if (keyValue == 14){
digitalWrite(greenPin, !digitalRead(greenPin)); // toggles LED ON/OFF

else{
digitalWrite(greenPin, LOW);
if (keyValue == 14){
digitalWrite(greenPin, !digitalRead(greenPin));






/********************************************************
// call to part of the sketch that will use the key number
*/

//*******************************************************
readKey = false; // rest the flag
delay(debounce); // debounce
}
}
void scanRow(){
for(int j =row1; j < (row4 +1); j++){
digitalWrite(j, HIGH);
}
digitalWrite(rowCounter , LOW); // switch on one row
}
void readColumn(){
foundColumn = digitalRead(columnCounter);
if(foundColumn == 0){
foundCol = true;
}
else{
foundCol=false;
noKey=noKey +1; // counter for number of empty columns
}
}
}
}
}
}
}
}
}
}

keypad.ino (2.88 KB)

Please include your code in the post instead of attaching; it's small enough. People often use phones or tablets and can't read ino attachments.

Please edit your post

type [code]
paste your code after that
type [/code] after that

Format your code using Auto Format in the IDE and you will see your problem.

UKHeliBob:
Format your code using Auto Format in the IDE and you will see your problem.

hi
I did wat you asked me to do
But i still can't find the problem (my dad wrote this code and now he's at work(I'm new to arduino so...))

Here is your code Auto formatted

/****************************************************
4x4 keyboard matrix
By Chris Rouse Oct. 2015
Connect:
Row 1 to Arduino pin 2
Row 2 to Arduino pin 3
Row 3 to Arduino pin 4
Row 4 to Arduino pin 5
Column A to Arduino pin 8
Column B to Arduino pin 9
Column C to Arduino pin 10
Column D to Arduino pin 11
Key identification:
(with connector at the top)
0 1 2 3
4 5 6 7
8 9 10 11
12 13 14 15
Connector:
Rows     Columns
X X X X  X X X X
1 2 3 4  A B C D
(Rows link keys from left to right,
columns link keys from top to bottom)
****************************************************/
int rowCounter = 0; // row counter
int columnCounter = 0; // column counter
int foundColumn = 0;
boolean foundCol = false;
int keyValue = 0;
int noKey = 0;
boolean readKey = false;
int debounce = 300; // set this to the lowest value that gives the best result
const int row1 = 2;
const int row2 = 3;
const int row3 = 4;
const int row4 = 5;
const int colA = 8;
const int colB = 9;
const int colC = 10;
const int colD = 11;
const int redPin = 6; // onboard LED
const int greenPin = 12;
const int yellowPin = 13;

void setup()
{
  Serial.begin(9600);
  pinMode(row1, OUTPUT);
  pinMode(row2, OUTPUT);
  pinMode(row3, OUTPUT);
  pinMode(row4, OUTPUT);
  pinMode(colA, INPUT_PULLUP);
  pinMode(colB, INPUT_PULLUP);
  pinMode(colC, INPUT_PULLUP);
  pinMode(colD, INPUT_PULLUP);
  //
  pinMode(redPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
  pinMode(yellowPin, OUTPUT);
  digitalWrite(redPin, LOW); // turn LED off
  digitalWrite(greenPin, LOW);
  digitalWrite(yellowPin, LOW);
}

void loop()
{
  if (noKey == 16) // no keys were pressed
  {
    readKey = true; // keyboard is ready to accept a new keypress
  }
  noKey = 0;
  for (rowCounter = row1; rowCounter < (row4 + 1); rowCounter++)
  {
    scanRow(); // switch on one row at a time
    for (columnCounter = colA; columnCounter < colD + 1; columnCounter++)
    {
      readColumn(); // read the switch pressed
      if (foundCol == true)
      {
        keyValue = (rowCounter - row1) + 4 * (columnCounter - colA);
        if (readKey == true && noKey == 15) // a key has been pressed
        {
          Serial.println(keyValue); // used for debug
          if (keyValue == 13)
          {
            digitalWrite(redPin, !digitalRead(redPin)); // toggles LED ON/OFF
            else
            {
              digitalWrite(redPin, LOW);
              if (keyValue == 14)
              {
                digitalWrite(greenPin, !digitalRead(greenPin)); // toggles LED ON/OFF
                else
                {
                  digitalWrite(greenPin, LOW);
                  if (keyValue == 14)
                  {
                    digitalWrite(greenPin, !digitalRead(greenPin));
                    /********************************************************
                    // call to part of the sketch that will use the key number
                    */
                    //*******************************************************
                    readKey = false; // rest the flag
                    delay(debounce); // debounce
                  }
                }
                void scanRow()
                {
                  for (int j = row1; j < (row4 + 1); j++)
                  {
                    digitalWrite(j, HIGH);
                  }
                  digitalWrite(rowCounter , LOW); // switch on one row
                }
                void readColumn()
                {
                  foundColumn = digitalRead(columnCounter);
                  if (foundColumn == 0)
                  {
                    foundCol = true;
                  }
                  else
                  {
                    foundCol = false;
                    noKey = noKey + 1; // counter for number of empty columns
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

When Auto formatted function definitions should start on the left margin, like loop() and setup()

Does the scanRow() function definitiaon start on the left margin ? If then why not ? Is the code block that precedes it terminated correctly with one (or possibly more) right curly brackets ?

              if (keyValue == 14)
              {
                digitalWrite(greenPin, !digitalRead(greenPin)); // toggles LED ON/OFF
                else
                {
                  digitalWrite(greenPin, LOW);
                  if (keyValue == 14)
                  {

The else block won't be executed if keyValue is 14, so it is pointless to test that keyValue is 14 in the else block. It will not be 14.

There is a Keypad library that properly handles reading 3x3, 3x4, and 4x4 keypads. Why not use that, instead of writing your own code, when you don't understand coding?

/Users/john/Documents/Arduino/sketch_jun27a/sketch_jun27a.ino: In function 'void loop()':
sketch_jun27a:46: error: 'scanRow' was not declared in this scope
     scanRow(); // switch on one row at a time
             ^
sketch_jun27a:76: error: a function-definition is not allowed here before '{' token
                 void scanRow() {
                                ^

The function is not declared because the function above it did not have amatching '}' for each '{'.

sketch_jun27a:57: error: expected '}' before 'else'
             else {
             ^
sketch_jun27a:61: error: expected '}' before 'else'
                 else {

These errors point out some of the places where a '}' was expected but not placed.
^

sketch_jun27a:99: error: expected '}' at end of input
 }
 ^
sketch_jun27a:99: error: expected '}' at end of input
sketch_jun27a:99: error: expected '}' at end of input
sketch_jun27a:99: error: expected '}' at end of input
sketch_jun27a:99: error: expected '}' at end of input
sketch_jun27a:99: error: expected '}' at end of input

And it looks like a bunch of other cases where '{' did not have a matching '}'. Check for matching brackets!

Check for matching brackets!

There may be some spare ones at the end of the program !

                  }
                }
              }
            }
          }
        }
      }
    }
  }
}