I want to make a game of Tic-tac-toe using an Arduino, LEDs and bouncy buttons. Hence I need nine inputs and nine outputs. But you see that an Arduino only has 13 I/O pins. So is there a way I can use the analog pins or a way to reduce the number of I/O pins using an ingenious way?
-
3possible duplicate of Is there a way to have more than 14 Output pins on arduino?Nick Gammon– Nick Gammon ♦2015年08月21日 21:30:41 +00:00Commented Aug 21, 2015 at 21:30
-
See Is there a way to have more than 14 Output pins on arduino? - there is a lengthy discussion there, with references.Nick Gammon– Nick Gammon ♦2015年08月21日 21:31:30 +00:00Commented Aug 21, 2015 at 21:31
-
I added an answer to the question Nick mentioned, with a note about accessing 7 I/O lines from the Atmega16U2 on the Uno.James Waldby - jwpat7– James Waldby - jwpat72015年08月22日 02:50:04 +00:00Commented Aug 22, 2015 at 2:50
-
Have a look at charlieplexingGreenonline– Greenonline2015年09月14日 00:56:49 +00:00Commented Sep 14, 2015 at 0:56
-
This question is similar to Creating an Arduino Tic Tac Toe game.sa_leinad– sa_leinad2018年01月16日 05:20:14 +00:00Commented Jan 16, 2018 at 5:20
2 Answers 2
Yes, just use the analog pins. The analog pins are both analog inputs and digital I/O pins. The functions happen to be shared on the pins, in the same way that the interrupt pins are shared with digital I/O, the TX and RX pins are shared with digital I/O and the SPI pins are shared with digital I/O.
Every I/O pin (analog or digital, etc.) can be used as digital I/O.
You can also reduce your required number of I/O pins by using a technique known as multiplexing.
For instance, to read nine buttons you could have them arranged (as in Tic-tac-toe) in three rows of three buttons. You then have three I/O pins for the columns and three I/O pins for the rows - that's just six I/O pins for nine buttons.
The technique is widely used for keypads, but they are just buttons, so the same technique can be applied to any buttons.
The same can go for LEDs. There are various specialist LED multiplexing techniques that allow for many LEDs to be driven from just a handful of I/O pins.
-
You can also multiplex buttons with LEDs, this way you just need 3 pins for commons + 3 pins for LEDs + 3 pins for inputs.Cano64– Cano642015年08月21日 19:06:17 +00:00Commented Aug 21, 2015 at 19:06
If multiplexing is too complicated for you, you can wire all buttons to one analog pin using resistors. This way you only need 9 pins for LEDs and 1 analog pin for buttons.
-
What I am planning to do is that use rgb leds, So if user 1 presses some button then red color and then next one green. So I guess that this method would not be able to work that way, because they require different voltages. And all this process have to be dynamic. I don't know which button will the user be pressing.Clarskon– Clarskon2015年08月22日 05:03:48 +00:00Commented Aug 22, 2015 at 5:03