69Views4Replies

Author Options:

Can someone please help?why does it say ROW0 was not declared in this scope in void setup? Answered

Can someone lase help?why does it say ROW0 was not declared in this scope in void setup?

int keyscan()

{
const int led2pin = 10;
const int led3pin = 9;
const int led4pin = 8;
const int buzzer = 12;
const int LidSw =  13;
const int ROW0 = 7;
const int ROW1 = 6;
const int ROW2 = 5;
const int ROW3 = 4;
const int COL0 = 3;
const int COL1 = 2;
const int COL2 = 1;

  const int keys[12]={
    1,2,3,4,5,6,7,8,9,10,11,12                  };
  int r=0;
  int c=0;
  int keypress=99;
  int ColState = 0;    //variable to store column state, 0 = low
}
void setup()
{
  pinMode(ROW0, OUTPUT);
}

  while(keypress=99)
  {         
    for(r=0; r<4; r++)                          //loop for 4 rows
    {
      digitalWrite(rows[r], HIGH);
      for(c=0;c<3;c++)                          //loop for 3 columns
      {
        ColState =  digitalRead(cols[c]);
        if(ColState==1)
        {
          digitalWrite(rows[r], LOW);  //reset row
          tone(BZR, 450, 500);
          ColState = 0;                //reset ColState variable
          keypress = keys[(r*3)+c];    //identify key pressed
          delay(500);                  //debounce
          return keypress;
        }
      }

      digitalWrite(rows[r], LOW);
    }
  }
}

Tags:Arduino

Discussions

0
None
lewisb42

6 years ago

The variables you declare in the keyscan() function are local to that function, i.e., they only exist inside it -- they are not visible outside the function.

That said, I can't see any reason not to move everything in keyscan() outside the function (making them what we call "global variables"). Doing so will make them visible to *all* functions in your sketch and should fix your problem.

0
None
endaralewisb42

Reply 6 years ago

that worked a treat man thanks for the help

0
None
steveastrouklewisb42

Reply 6 years ago

Thereby lies the path to maaadness. Globals are a major PITA. Use a class, and do the job properly....

0
None
lewisb42steveastrouk

Reply 6 years ago

Normally I'd agree, but for most simple Arduino sketches (especially for beginners) globals are fine. And for beginners who haven't yet learned classes, globals are pretty much a necessity.