Go Down

Topic: Help with 2x2 matrix button board (Read 2369 times) previous topic - next topic

johncc

If you remove the diode and replace with jumper (or better would be  1-to-5k resistor ) , you can do without the external pull-down resistor and wire the switches between the arduino pin and Gnd.

johncc

#31
Jan 31, 2013, 01:40 am Last Edit: Jan 31, 2013, 01:42 am by johncc Reason: 1
In that case your hardware test code would be simply like this:

Code: [Select]
// Button sense
const int button1 = A1;  // or whichever you wire to
const int button2 = A2;
const int button3 = A3;
const int button4 = A4;

void setup()
{
// Button sense
pinMode(button1, INPUT_PULLUP);
//pinMode(button2, INPUT_PULLUP);
//pinMode(button3, INPUT_PULLUP);
//pinMode(button4, INPUT_PULLUP);
}
void loop()
{
Serial.print( digitalRead(button1));  Serial.print("\t");
//Serial.print( digitalRead(button2)); Serial.print("\t");
//Serial.print( digitalRead(button3)); Serial.print("\t");
//Serial.print( digitalRead(button4));
Serial.println();
delay(250);
}

MaJiG

Shouldn't the input pins be digital and not analog?

And the switches should go from the digital pin to GND when pressed, yes?

johncc


Shouldn't the input pins be digital and not analog?

Any pin (including "analog pin") can be used as digital. 

Quote

And the switches should go from the digital pin to GND when pressed, yes?


Yes, they are wired with one side to the aruduino pin, and the other side to GND.

Go Up