user10408: 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?

user6372: 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.


user4143: 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 Matrix Keypad how-to

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.

How to Multiplex an LED Grid... (YouTube)
Charlieplex Library for Arduino


10408: <p>I want to make a game of <a href="https://en.wikipedia.org/wiki/Tic-tac-toe" rel="nofollow">Tic-tac-toe</a> 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?</p>
 6372: <p>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.</p>

<p><a href="https://i.stack.imgur.com/cxlSz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cxlSz.png" alt="enter image description here"></a></p>
 4143: <p>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.</p>

<p>Every I/O pin (analog or digital, etc.) can be used as digital I/O.</p>

<p>You can also reduce your required number of I/O pins by using a technique known as <em>multiplexing</em>.</p>

<p>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.</p>

<p>The technique is widely used for keypads, but they are just buttons, so the same technique can be applied to any buttons.</p>

<ul>
<li><em><a href="http://playground.arduino.cc/Main/KeypadTutorial" rel="nofollow">The Matrix Keypad how-to</a></em></li>
</ul>

<p>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.</p>

<ul>
<li><em><a href="https://www.youtube.com/watch?v=MmCGDJ90Qt4" rel="nofollow">How to Multiplex an LED Grid...</a></em> (YouTube)</li>
<li><em><a href="http://playground.arduino.cc/Code/Charlieplex" rel="nofollow">Charlieplex Library for Arduino</a></em></li>
</ul>
