74Views2Replies

Author Options:

can anybody tell me why my return command in void loop isnt working? Answered

int keyscan()

{

 
  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
}
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;
  int keypress=99;
   int r=0;
  int c=0;
  int ColState = 0;
void setup()
{
  pinMode(ROW0, OUTPUT);
  pinMode(ROW1, OUTPUT);
  pinMode(ROW2, OUTPUT);
  pinMode(ROW3, OUTPUT);
  pinMode(COL0, INPUT);
pinMode(COL1, INPUT);
  pinMode(COL2, INPUT);
 
}
  void loop()
  {while(keypress=99)
  {          
    for(r=0; r<4; r++)                          //loop for 4 rows
    {
      digitalWrite(ROW0, HIGH);
      for(c=0;c<3;c++)                          //loop for 3 columns
      {
        ColState =  digitalRead(COL0);
        if(ColState==1)
        {
          digitalWrite(ROW0, LOW);  //reset row
          tone(buzzer, 450, 500);
          ColState = 0;                //reset ColState variable
          keypress = ROW0+COL0;    //identify key pressed
          delay(500);                  //debounce
        return keypress;
        }
      }

      digitalWrite(ROW0, LOW);
    }
  }
}

Tags:arduino

Discussions

0
None
steveastrouk

6 years ago

Better to ask this sort of question in the "Community- answers" section

0
None
caitlinsdad

6 years ago

Have you used the sample code to just get one switch working? It's all on the tutorials at arduino.cc or from the IDE. Where are you sensing a key press?