Reputation: 25
I've been recently working with an Arduino - trying to develop a program. The program should find which pins a keypad button is connected to in order for it to be easier to use libraries such as "keypad". I don't need to use a multimeter.
I'm currently working with a Megarduino and an LCD keypad shield.
This is the code that I have for scanning the keypad pins connected to the Arduino but I can't make it work.
There is previously a pin object array that has 9 pins with the following attributes: arduinoPin
, scannedPin
, basePin
for (int kpdBasePin=2; kpdBasePin<NUMPINS; kpdBasePin++)
{
scanPins(kpdBasePin); // scan all pins less than kpdBasePin.
}
void scanPins(int baseKpdPin)
{
// Set base_pin output to LOW to begin scan process.
int base = kpdPin[baseKpdPin].arduinoPin;
pinMode(base, OUTPUT);
digitalWrite(base, LOW);
// Scan all pins up to, but not including, the base_pin. A LOW indicates a
// key is being pressed.
for (int scannedKpdPin = 1; scannedKpdPin < baseKpdPin; scannedKpdPin++)
{
// Created a local variable for readability.
int arduinoPin = kpdPin[scannedKpdPin].arduinoPin;
int keyState = !digitalRead(arduinoPin);
if (keyState)
{
storePins(scannedKpdPin, base); //method to store both pins
}
}
// End pin scanning process.
digitalWrite(base, HIGH);
pinMode(base, INPUT_PULLUP);
}
Is there something wrong with this code?
Upvotes: 1
Views: 223