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).seven segment display show 0000 when I tried to multiply the value with keypad value it show wrong answer . if i type t=1200*20 ; no value enter from keypad it show wright answer on serial monitor and seven segment display
#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);
}