Helo,
My final aim is to do an 8x8 keypad, presently I have 4x4 keypad available,so am trying out with that. Am using Arduino Uno R3 compatible. My setup is as in the attached: My problem is how to detect the column that went low on key press as to determined the key. Presently any key on Col 0 returns 240; Col1 returns 232; etc (dont know if that is ok. )Please help.
Am coding with visual studio 2015 cSharp +Visual Micro My code is as follow:
const int kbdRows = 4;
const int kbdCols = 4;
int LatchIn = 3; //165 pin1
int ClockPin = 5; // 595 pin11 & 165 pin2
int DataIn = 2; //165 pin9
int LatchOut = 6; // 595 pin12
int DataOut = 7; //595 pin14
int led = 7;
byte mask = 0x80;
byte lastmask = 0x10;
byte incoming=0 ;
byte dataOuttest;
byte dataIntest;
int PinState = 0;
char keys[kbdRows][kbdCols] =
{
{ '1','2','3','4' },
{ '5','6','7','8' },
{ '9','0','A','B' },
{ 'C','D','E','F' }
};
byte KeyDown()
{
//595 Here
for (int row = 0; row < kbdRows; row++)
{
digitalWrite(ClockPin, LOW);
delayMicroseconds(5);
digitalWrite(LatchOut, LOW);//
shiftOut(DataOut, ClockPin, LSBFIRST, mask);
digitalWrite(LatchOut, HIGH);//
digitalWrite(ClockPin, HIGH);
delay(100);
Serial.println(" ");
Serial.print("Row: "); // here was to test for Data Shift Out
Serial.print(row);
Serial.print(" ");
Serial.print("Mask: ");
Serial.println(mask);
Serial.println(" ");
Serial.println(" ");
delay(100);
//165 Here
for (int col = 0; col < kbdCols; col++)
{
digitalWrite(ClockPin, LOW);
digitalWrite(LatchIn, LOW);
delayMicroseconds(5);
digitalWrite(LatchIn, HIGH);
incoming = shiftIn(DataIn, ClockPin, LSBFIRST);
digitalWrite(ClockPin, HIGH);
Serial.print("Col: ");
Serial.println(col);
Serial.print("InComing: ");
Serial.println(incoming);
/////if(incoming & mask)/////////////////
///{
/// byte keypress = keys[row][col];
/// Serial.print("KeyPRESS: ");
/// Serial.println(keypress); ////////////// here is my probs, dont know how to return the pressed key with my setup
/// }// end of if
delay(600);
} // end of col
if (mask == lastmask)
mask = 0x80;
else
mask = mask >> 1;
} // row end
}
void setup()
{
/* add setup code here */
pinMode(ClockPin, OUTPUT);
pinMode(DataOut, OUTPUT);
pinMode(DataIn, INPUT);
pinMode(LatchOut, OUTPUT);
pinMode(LatchIn, OUTPUT);
digitalWrite(LatchOut, LOW);
digitalWrite(ClockPin, LOW);
Serial.begin(9600);
digitalWrite(led, HIGH);
}
void loop()
{
/* add main program code here */
void setup()
{
/* add setup code here */
pinMode(ClockPin, OUTPUT);
pinMode(DataOut, OUTPUT);
pinMode(DataIn, INPUT);
pinMode(LatchOut, OUTPUT);
pinMode(LatchIn, OUTPUT);
digitalWrite(LatchOut, LOW);
digitalWrite(ClockPin, LOW);
Serial.begin(9600);
digitalWrite(led, HIGH);
}
void loop()
{
/* add main program code here */
KeyDown();
delay(300);
}