I have been unsuccessful in getting the analog pins to work "transparently" as digital inputs and outputs.
HW: 3x4 matrix keypad (SparkFun COM-08653) connected to pure digital pins works fine, eg D7..D13.
When connected to analog pins, and #defines changed, associated rows/cols don't respond, eg. D2..D6, D14, D15, where the latter two don't respond.
I'm trying to reserve 7 digital pins for LCD output, 2 for serial, then use 5 for keypad, plus the two analog pins.
Is there some special initialization to use analog pins in digital mode?
I tried inserting a delay after each write of a col or read of a row, thinking the analog circuits needed time to recover, but it didn't help.
Here's my code... TIA for any suggestions. --Jeff
/* Keypad Testing: read keypad, write serial
2008-12-18
*/
// arduino pin numbers associated with rows/cols of keypad matrix
#define KPD_C1 2
#define KPD_C2 14 // 7 OK, problem when 14
#define KPD_C3 4
#define KPD_R1 15 // 8 OK, problem when 15
#define KPD_R2 6
#define KPD_R3 5
#define KPD_R4 3
byte kpd_cols[3] = {KPD_C1, KPD_C2, KPD_C3};
byte kpd_rows[4] = {KPD_R1, KPD_R2, KPD_R3, KPD_R4};
char kpd_keys[] = "123456789*0#";
void InitKeypad()
{
int i;
for(i=0; i<4; i++) pinMode(kpd_rows*, INPUT); // rows are inputs*
for(i=0; i<4; i++) digitalWrite(kpd_rows*, HIGH); // enable pull-ups*
for(i=0; i<3; i++) pinMode(kpd_cols*, OUTPUT); // cols are outputs*
for(i=0; i<3; i++) digitalWrite(kpd_cols*, HIGH); // cols default high*
}
byte GetKey()
{
* byte k = 0;*
* for(byte col=0; col < 3; col++)*
* {*
* digitalWrite(kpd_cols[col], LOW); // send a col low*
* delay(1);*
* for(byte row=0; row < 4; row++)*
* {*
* byte x=digitalRead(kpd_rows[row]);
_ delay(1);
if (x == 0) // see if the row caught it*
* {
Serial.print("kpc=");_
Serial.print(kpd_cols[col], DEC);
_ Serial.print(" kpr=");_
Serial.print(kpd_rows[col], DEC);
_ Serial.print(" col=");
Serial.print(col, DEC);
Serial.print(" row=");
Serial.print(row, DEC);_
k = kpd_keys[col+(3row)];
* delay(500); // debounce*
* break;*
* }*
* }*
* digitalWrite(kpd_cols[col], HIGH);
_ }
return k;
}
void setup()
{
InitKeypad();
Serial.begin(9600);
Serial.println("Going...");
}
void loop()
{
byte key = GetKey();
if (key > 0)
{
Serial.print(" key=");
Serial.println(key);
}
}
[/quote]*_