+ Post New Thread
Results 1 to 6 of 6
  1. #1
    Full Member level 3
    Points: 1,071, Level: 7

    Join Date
    Oct 2015
    Posts
    153
    Helped
    0 / 0
    Points
    1,071
    Level
    7

    Arduino Error 'keypadEvent' was not declared in this scope

    Hi! I am trying to use the keypad.addEventListener() to call an event I did use it with keypadEvent,and then compiling my code gives me an Error 'keypadEvent' was not declared in this scope. Can you please help me where might have I gone wrong.
    Code:
    #include <Keypad.h>
    
    //pin assignments
    int latchPin = 15;                    
    int clockPin = 14;                    
    int dataPin = 16;                     
    int keySwitch = 9;                   
    int ledActual = 17;                   
    int ledTarget = 18;                  
    int ledTactTime = 19;                
    
    
    
    //global variables
    byte digitBuffer[6] = {0};
    
    int digitScan = 1;
    
    byte valueKeypad = 0;
    
    byte num = 0;
    
    //keypad
    const byte ROWS = 4; //four rows
    const byte COLS = 4; //three columns
    char keys[ROWS][COLS] = {
      {'1','2','3','A'},
      {'4','5','6','B'},
      {'7','8','9','C'},
      {'#','0','*','D'},
    };
    byte rowPins[ROWS] = {0 , 1, 2, 3}; //connect to the row pinouts of the keypad
    byte colPins[COLS] = {4, 5, 6, 7};//nnect to the column pinouts of the keypad
    
    Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS );
    
    
    
    //display 0,1,2,3,4,5,6,7,8,9:
    byte datArray[10] = {B01111101, B00100001, B01010111, B01110011, B00101011, B01111010, B01111110, B01100001, B01111111, B01111011};
    
    void setup()
    {
     //Serial.begin(9600);
    
      //pin designation
      pinMode(latchPin, OUTPUT);
      pinMode(clockPin, OUTPUT);
      pinMode(dataPin, OUTPUT);
    
      pinMode(keySwitch, INPUT);
      pinMode(ledActual, OUTPUT);
      pinMode(ledTarget, OUTPUT);
      pinMode(ledTactTime, OUTPUT);
    
    
    
      //initialize display
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin,clockPin, MSBFIRST, datArray[0]);
      shiftOut(dataPin,clockPin, MSBFIRST, datArray[0]);
      shiftOut(dataPin,clockPin, MSBFIRST, datArray[0]);
      shiftOut(dataPin,clockPin, MSBFIRST, datArray[0]);
      digitalWrite(latchPin, HIGH); //pull the latchPin to save the data
    
      keypad.addEventListener(keypadEvent);
     }
    
    void keypadEvent(KeypadEvent key)
    {
      if (keySwitch == LOW)
      {
      switch(keypad.getState())
      {
        case PRESSED:
            switch(key);
              {
                  case 'A':
                       digitalWrite(ledActual, HIGH);
                       //transmit data to the display - Actual Value
                  break;
    
                  case '3':
                       digitalWrite(ledTarget, HIGH);
                       //transmit data to the display - Target Value
                  break;
    
                  case '2':
                       digitalWrite(ledTactTime, HIGH);
                       //transmit data to the display - Time Value
                  break;
    
                  case '1';
                        digitalWrite(ledActual, LOW);
                        digitalWrite(ledTarget, LOW);
                        digitalWrite(ledTactTime, LOW);
                       //save the Actual Value to the Actual Variable
                  break;
              }
        break;
    
        case RELEASED:
            switch(key);
              {
                  case 'A':
                       digitalWrite(ledActual, HIGH);
                       keypadAction();
                       //transmit data to the display - Actual Value
                  break;
    
                  case '3':
                       digitalWrite(ledTarget, HIGH);
                       keypadAction();
                       //transmit data to the display - Target Value
                  break;
    
                  case '2':
                       digitalWrite(ledTactTime, HIGH);
                       keypadAction();
                       //transmit data to the display - Time Value
                  break;
    
                  case '1';
                       digitalWrite(ledActual, LOW);
                       digitalWrite(ledTarget, LOW);
                       digitalWrite(ledTactTime, LOW);
                       //save the Actual Value to the Actual Variable
                  break;
              }
        break;
    
        case HOLD:
            switch(key);
              {
                  case 'A':
                       digitalWrite(ledActual, HIGH);
                       //transmit data to the display - Actual Value
                  break;
    
                  case '3':
                       digitalWrite(ledTarget, HIGH);
                       //transmit data to the display - Target Value
                  break;
    
                  case '2':
                       digitalWrite(ledTactTime, HIGH);
                       
                  break;
    
                  case '1';
                       digitalWrite(ledActual, LOW);
                       digitalWrite(ledTarget, LOW);
                       digitalWrite(ledTactTime, LOW);
                       
                  break;
              }
        break;
      }
      }
    }

    •   Alt19th April 2017, 06:26

      advertising

        
       

  2. #2
    Advanced Member level 5
    Points: 11,441, Level: 25
    Achievements:
    7 years registered

    Join Date
    Apr 2010
    Posts
    1,752
    Helped
    382 / 382
    Points
    11,441
    Level
    25

    Re: Arduino Error 'keypadEvent' was not declared in this scope

    add
    void loop()
    {
    //the keypad case statements here...
    }
    to your code module.



    •   Alt19th April 2017, 06:41

      advertising

        
       

  3. #3
    Full Member level 3
    Points: 1,071, Level: 7

    Join Date
    Oct 2015
    Posts
    153
    Helped
    0 / 0
    Points
    1,071
    Level
    7

    Re: Arduino Error 'keypadEvent' was not declared in this scope

    Quote Originally Posted by srizbf View Post
    add
    void loop()
    {
    //the keypad case statements here...
    }
    to your code module.
    I just did, but I have found the same error..



    •   Alt19th April 2017, 06:53

      advertising

        
       

  4. #4
    Advanced Member level 5
    Points: 11,441, Level: 25
    Achievements:
    7 years registered

    Join Date
    Apr 2010
    Posts
    1,752
    Helped
    382 / 382
    Points
    11,441
    Level
    25

    Re: Arduino Error 'keypadEvent' was not declared in this scope

    What happens when you write

    keypad.addEventListener(keypadEvent);

    as
    within the void loop()
    {
    keypad.addEventListener(keypadEvent);
    ........
    }

    and remove it from setup()


    1 members found this post helpful.

  5. #5
    Full Member level 3
    Points: 1,071, Level: 7

    Join Date
    Oct 2015
    Posts
    153
    Helped
    0 / 0
    Points
    1,071
    Level
    7

    Re: Arduino Error 'keypadEvent' was not declared in this scope

    I have made it worked. It just re-arranged each function. Thanks for the help anyway.



    •   Alt20th April 2017, 02:49

      advertising

        
       

  6. #6
    Full Member level 3
    Points: 1,071, Level: 7

    Join Date
    Oct 2015
    Posts
    153
    Helped
    0 / 0
    Points
    1,071
    Level
    7

    Arduino "no_Key" can it be used in multiple function

    Hi! I am trying to used the "no_key" of arduino keypad with multiple function, as the first function is called, it works perfectly, but when the next function(also uses the "no_key") is called keypad is no longer responding. Can the "no_key" be used in multiple function?

    first function:
    Code:
    void keypadPress()
    {
      
      char key = keypad.getKey();
    
      if(keypadActionFlag == true)
       {
          if(key != NO_KEY)
             {
    
                if (key == 'A')
                  {
                      
                      digitalWrite(ledActual, HIGH);
                      digitalWrite(ledTarget, LOW);
                      digitalWrite(ledTactTime, LOW);
            
                      keypadActualFlag = true;
            
                      //transmit data to the display - Actual Value
                  }
    
               else if (key == '3')
                  {
                    
                    digitalWrite(ledTarget, HIGH);
                    digitalWrite(ledActual, LOW);
                    digitalWrite(ledTactTime, LOW);
            
                    keypadTargetFlag = true;
           
                    //transmit data to the display - Target Value
                  }
    
              else if (key == '2')
                  {
     
                    digitalWrite(ledTactTime, HIGH);
                    digitalWrite(ledActual, LOW);
                    digitalWrite(ledTarget, LOW);
                    
                    keypadTactTimeFlag = true;
            
                    //transmit data to the display - Time Value
                  }
       
             else if (key == '1')
                  {
                    digitalWrite(ledActual, LOW);
                    digitalWrite(ledTarget, LOW);
                    digitalWrite(ledTactTime, LOW);
                    
                    keypadActualFlag = false;
                    keypadTargetFlag = false;
                    keypadTactTimeFlag = false;
                    
                    //save the Actual Value to the Actual Variable    
                  }
    
              else
                  {
                      //do nothing
                  }
      
        }
       }
    
       else
       {
        //do nothing
       }
    }
    2nd function:
    Code:
    void keypadAction()
    {
    if ((keypadActualFlag == true) || (keypadTargetFlag == true) || (keypadTactTimeFlag == true))
    {
      
      char keyPad = keypad.getKey();
      
      //keypad printing of value
      if (keyPad != NO_KEY)
      {
       
           if (keyPad == 'D')
              {
                  //delay(300);
                  num = datArray[1];
                  // Serial.println(num);
                  digitalWrite(latchPin, LOW); 
                  Serial.println(num);
                  Serial.println("Keypress");
              }
            
            
            else if (keyPad == 'C')
              {
                  // delay(300);
                  num = datArray[2];
                  digitalWrite(latchPin, LOW);
                  Serial.println(num);
              }
            
        
            else if (keyPad == 'B')
              {
                  //  delay(300);
                  num = datArray[3];
                  digitalWrite(latchPin, LOW);
                  Serial.println(num);
              }
            
        
            else if (keyPad == '*')
              {
                  num = datArray[4];
                  Serial.println(num);
                  digitalWrite(latchPin, LOW);
                  // delay(300);
              }
            
        
            else if (keyPad == '9')
              {
                   //delay(300);
                   num = datArray[5];
                   Serial.println(num);
                   digitalWrite(latchPin, LOW);
              }
             
         
             else if (keyPad == '6')
              {
                  // delay(300);
                  //  delay(200);
                  num = datArray[6];
                  Serial.println(num);
                  digitalWrite(latchPin, LOW);
              }
             
    
             else if (keyPad == '0')
              {
                  num = datArray[7];
                  Serial.println(num);
                  digitalWrite(latchPin, LOW);
              }
             
        
             else if (keyPad == '8')
              {
                  num = datArray[8];
                  Serial.println(num); 
                  digitalWrite(latchPin, LOW); 
              }
             
        
             else if (keyPad == '5')
              {
                  num = datArray[9];
                  digitalWrite(latchPin, LOW);
                  Serial.println(num);
              }
             
             
            else if (keyPad == '7')
              {
                  // delay(300);
                  num = datArray[0];
                  digitalWrite(latchPin, LOW);
                  Serial.println(num);
              }
             
    
             else if (keyPad == '4')
              {
                  digitScan = 0;
        
                  digitalWrite(latchPin, LOW);
                  shiftOut(dataPin,clockPin, MSBFIRST, datArray[0]);
                  digitalWrite(latchPin, HIGH); //pull the latchPin to save the data
                  //delay(250); //wait for a second
             }
            
      
            else if (keyPad == '#')
              {
                  digitScan = 0;
        
                  digitalWrite(latchPin, LOW);
                  shiftOut(dataPin,clockPin, MSBFIRST, datArray[0]);
                  digitalWrite(latchPin, HIGH); //pull the latchPin to save the data
                  //delay(250); //wait for a second
              }
    
             else
             {
              //do nothing
             }
    
           
      
    
        digitBuffer = num;
      
        displayValue();
    
      
      }
    
     /* else
      {
        Serial.println("keypadPress else");
      }*/
    }
    
    else
    {
      // do nothing
    }
    }



--[[ ]]--