Keypad not working properly with Arduino. show wrong value on serial monitor

type or paste code here
 #include <Keypad.h>
 #include "LedControl.h"
LedControl lc = LedControl(11,3,4,1); //DIN, SCK, LOAD,1xMAX7219
int a=20;
int b=30;
int c=37;
int d=40;


const byte ROWS = 4; 
const byte COLS = 4; 

char hexaKeys[ROWS][COLS] = {
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'*', '0', '#', 'D'}
};

byte rowPins[ROWS] = { A0, A1, A2, A3}; 
byte colPins[COLS] = { A4, 5, 6, 7}; 

Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS); 

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
//  inputString.reserve(10);
  lc.shutdown(0,false);  // Wake up the display
  lc.setIntensity(0,7);
   //lc2.setIntensity(0,7);// Set Brightness 0-15
  lc.clearDisplay(0);  // Clear display
}

void loop() {
  // put your main code here, to run repeatedly:
    char customKey = customKeypad.getKey();
    customKey=customKey-'0';

    if(customKey=='A'){// when press it go to function shahbaz.
      shahbaz();
      }

}





void shahbaz(){
  
  
  
  
 char customKey = customKeypad.getKey();
 customKey=customKey-'0';
    long  int t=a*customKey;
      
      Serial.print(t);
      
      Serial.print(customKey);
       long   int t=customKey*a; // here get value from keypad and multiply with value of //int a but it show nothing when i print this value on serial monitor it show -960 

  int digitOne =    (t%10);
    int digitTwo =    (t/10)%10;
      int digitThree =  (t/100)%10;
      int digitFour =   (t/1000)%10;
      int digitFive =   (t/10000)%10;
      int digitSix =    (t/100000)%10;
      int digitSeven=   (t/1000000)%10;
      int digitEight =  (t/10000000)%10;


    //MSB digitEight, LSB digitOne

      lc.setDigit(0,7,digitEight,false);

      lc.setDigit(0,6,digitSeven,false);

      lc.setDigit(0,5,digitSix,false);

      lc.setDigit(0,4,digitFive,false);

      lc.setDigit(0,3,digitFour,false);

      lc.setDigit(0,2,digitThree,false);

      lc.setDigit(0,1,digitTwo,false);


      lc.setDigit(0,0,digitOne,false);
      delay(1000);

  }





  

Good work posting the code in code tags... but was there a question you are looking for help on?

You posted the wrong code. There is no "else if". Nothing is printed to serial monitor.

yes i want some help

Then clearly tell us what is not working as you expect.

when i press A from keypad it call the function shahbaz() , then i enter some value from keypad which multiply with int a and show results on seven segment .but show no results on seven segment display.when i print this result on serial.monitor
it show wrong answer like(-960, 000).

when i press A from keypad it call the function shahbaz() , then i enter some value from keypad which multiply with int a and show results on seven segment .but show no results on seven segment display.when i print this result on serial.monitor
it show wrong answer like(-960, 000).

Your code doesn't compile

then how i compile it?

remove the code the compiler doesn't like...

i don't understand

Correct. You should try to Google Arduino for beginners.

you are right for google arduino for beginners.

haha

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.