Go Down

Topic: LED and Button Matrix (Read 137 times) previous topic - next topic

BojanSof

I have created a simple Memory game using Arduino. I have created two matrices, 3x3 for now, one for tactical switches, and another for leds, on same board. The idea is simple: Arduino creates random blinks on led matrix, then the user has to press the correct order of blinks using the tactical switches. But in this way, I have to use 6 pins for the LED matrix and 6 pins for the switch matrix. Is there a way I can combine both matrices in one, so I would use only 6 pins?

PaulRB


Paul__B

#2
Aug 11, 2018, 02:10 pm Last Edit: Aug 11, 2018, 02:17 pm by Paul__B Reason: Deep Thought
So, a very short answer for a short question.   :smiley-lol:  :smiley-lol:

The point is, you need to explain your situation properly.  This appears to be a cross between "Tic Tac Toe" and "Simon".  It seems you only wish to light one LED at a time.  This makes the situation much easier as there is no problem sharing pin current between more than one LED as happens in multiplexing displays.

To light a LED, you pull the cathode LOW and have a resistor (something between 220 Ohm and 1k) from the anode to a pin you pull HIGH.

To sense a button, you pull one side LOW and connect the other side to a pin which is set to a pinMode of INPUT_PULLUP.

What is common to these scenarios?  It is pulling one side LOW, so you can use the same three pins for one side of each button - we will call these "rows" - and the LED cathodes.  These three pins are never set HIGH, when not active, they are set to INPUT.

Then the switch columns connect to three pins with a pinMode of INPUT_PULLUP, and the LED anodes connect with a series resistor each, to another three pins.

Total nine pins.  Pressing more than one button at once may cause funny things to happen - that can be fixed if necessary.

Oh!  Yes, you can use only six pins.  Just wire a button across each LED.

To light the LED, you pull the anode side HIGH and the cathode side LOW.  To sense the button, you pull the anode side LOW and the cathode side to INPUT_PULLUP.  The resistors (470 Ohm would be good) in series with the pins limit the current when the LED is shorted out and need I say it, the LED obviously cannot light while the button is pressed.

BojanSof


Go Up