#define row_scan_delay 5 // delay between powering of two rows
#define column_scan_delay 5 // delay between powering of two columns ( this add to total delay by for rows)
char keypad[4][4] = {{'1','2','3','A'},{'4','5','6','B'},{'7','8','9','C'},{'*','0','#','D'}}; // This is char type 1D array 4 rows and 4 columns (16 elements (4x4))
char keyPressed;
////////////////////////////////////////////////////// SSD Codes
const int dataPin1 = 10; //* DS / // change to 10 and use that pin to wire it
const int clockPin1 = 11; //* SHCP /
const int latchPin1 = 12; //* STCP /
//////////////////////////////////////////////////////// End of SSD codes
int zero;
int one;
int two;
int three;
int four;
int five;
int six;
int seven;
int eight;
int nine;
//int DecimalCodes[] = {252, 96, 218, 242, 102, 182, 190, 224, 254, 246};
void SSDdisplay( int digitCode);
void setup()
{
Serial.begin(115200);
for(int i = 2; i<6; i++)
{
pinMode(i,OUTPUT);
}
for(int i = 6; i<10; i++)
{
pinMode(i,INPUT);
}
//////////////////////////////////////////////////////////////////////////// SSD codes
for(int i = 10; i<13; i++) ////################## this not updated in prevous program
{
pinMode(i, OUTPUT);
}
zero = 252; //0b11111100; //0
one = 96; //0b01100000; //1
two = 128; //0b11011010; //2
three = 242; //0b11110010; //3
four = 102; //0b01100110; //4
five = 182; //0b10110110; //5
six = 190; //0b10111110; //6
seven = 224; //0b11100000; //7
eight = 254; //0b11111110;//8
nine = 246; //0b11110110;//9
///////////////////////////////////////////////////////////////////////////// End of SSD codes
}
void loop()
{
for(int i=2; i<6; i++) //power up each column one by one
{
if(i>2)
{
digitalWrite(i-1, LOW); //power down previous column
//Serial.print(i-1);
//Serial.println("LOW");
}
if(i==2)
{
digitalWrite(5, LOW); // to go back to column 1
//Serial.print(5);
//Serial.println("LOW");
}
digitalWrite(i, HIGH); // power up the column
//Serial.print(i);
//Serial.println("HIGH");
//Serial.println("delay");
int row;
int clonmn =i-1; // column number from i(i is pin number)
bool column_State; // low or high 0 or 1
for(int j =6;j<10;j++ ) // scan/ read each row
{
row = j-5; // row number = pin number - 5
column_State= digitalRead(j); // read the row
if(column_State==1) // print row and columd only when row pin is high
{
Serial.print(clonmn);
Serial.print(" ");
Serial.print(row);
Serial.print(":");
Serial.print(column_State);
Serial.print(" key : ");
keyPressed = keypad[row-1][clonmn-1];
Serial.println(keyPressed);
//DisplaayInSSD( keyPressed);
}
delay(row_scan_delay);
}
delay(column_scan_delay);
}
//////////////////////////////////////////////////////////////////////////////////// SSD codes
//display_inSSD(1);
//DisplaayInSSD('1');
SSDdisplay(96);
delay(1000);
SSDdisplay(128);
//display_inSSD(2);
//DisplaayInSSD('2');
delay(1000);
SSDdisplay(182);
delay(1000);
SSDdisplay(242);
delay(1000);
////////////////////////////////////////////////////////////////////////////////// End of SSD codes
}
void temp( int j) // j for temp
{
int i; // for temp
//Serial.println(digitalRead(j));
if(digitalRead(j))
{
Serial.print(i);
Serial.print(" ");
Serial.print(j);
Serial.println();
}
}
///////////////////////////////////////////////////////SSD codes
void SSDdisplay( int digitCode)//decimal code
{
digitalWrite(latchPin1, LOW);
shiftOut(dataPin1, clockPin1, LSBFIRST, digitCode);
digitalWrite(latchPin1, HIGH);
}
void display_inSSD(int num) // to test SSD
{
switch (num)
{
case 1:
SSDdisplay(96);
break;
case 2:
SSDdisplay(128);
// do something when var equals 2
break;
default:
// if nothing else matches, do the default
// default is optional
break;
}
}
void DisplaayInSSD( char keypresd) // to directly display the char by keypad on SSD
{
switch (keypresd)
{
case '1':
SSDdisplay(96);
Serial.println("display 1");
break;
case '2':
SSDdisplay(128);
Serial.println("display 2");
// do something when var equals 2
break;
default:
// if nothing else matches, do the default
// default is optional
break;
}
}
///////////////////////////////////////////////////// End of SSD codes