Display
The display on the Arcade Coder is a 12x12 LED matrix. Each pixel works in 3-bit colour (giving 8 total colours). Each pixel also serves as a button.
The matrix is split into groups by row. The multiplexer selects the rows to be drawn to, and the data is sent to the rows via the shift register.
Pins
HC595 Shift Register
| ESP | Shift Register |
|---|---|
| GPIO5 | Data In |
| GPIO17 | Clock |
| GPIO16 | Latch |
| GPIO4 | Output Enable |
For the output enable pin, a high signal enables output and a low signal disables it. Practically, set high when writing data.
ICN2012 Multiplexer
The rows are selected by setting different combinations on the multiplexer.
| ESP | Multiplexer |
|---|---|
| GPIO19 | A0 |
| GPIO18 | A1 |
| GPIO21 | A2 |
| A0 | A1 | A2 | Rows |
|---|---|---|---|
| 0 | 0 | 0 | Unknown/Off |
| 0 | 0 | 1 | 4 & 9 |
| 0 | 1 | 0 | 1 & 6 |
| 0 | 1 | 1 | 6 & 12 |
| 1 | 0 | 0 | 5 & 10 |
| 1 | 0 | 1 | 3 & 8 |
| 1 | 1 | 0 | 2 & 7 |
| 1 | 1 | 1 | Input Reading |
Data Format
The data sent to each of the two rows is 9 bytes (or 72 bits). The bits are inversed, with a 0 representing the on state and a 1 representing off.
For testing, sending 9 bytes of 0xffffffff should result in all white LEDs, and 0x00000000 should turn off all the LEDs.
The table below is ordered with most significant bit first.
| Byte | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 |
|---|---|---|---|---|---|---|---|---|
| 1 | Green, pixels 5-12, top row | |||||||
| 2 | Red, pixels 5-12, top row | |||||||
| 3 | Blue, pixels 5-12, top row | |||||||
| 4 | Green, pixels 1-4, bottom row | Green, pixels 1-4, top row | ||||||
| 5 | Red, pixels 1-4, bottom row | Red, pixels 1-4, top row | ||||||
| 6 | Blue, pixels 1-4, bottom row | Blue, pixels 1-4, top row | ||||||
| 7 | Green, pixels 5-12, bottom row | |||||||
| 8 | Red, pixels 5-12, bottom row | |||||||
| 9 | Blue, pixels 5-12, bottom row | |||||||
Implementation Notes
In a nutshell, to send data to the display:
- Set multiplexers to the row to be displayed to.
- Send data via shift registers to the selected row.
- Loop over rows as necessary.
Setting Multiplexers
- Using the table above, set the multiplexer pins A0, A1 & A2 to the relevant values to select a row.
- Wait a short delay to wait for the output to stabilize (e.g. 5µs).
Sending Data to Shift Registers
- Set output enable high and latch low to begin transmission.
- Write data out using the SPI bus for accurate timing. I used an SPI speed of 8MHz. Otherwise, send each bit (MSB), setting the clock high, then low after each bit with a short delay.
- Set latch high to send the data out from the shift register to the row.
- Wait a short delay (e.g. 2µs).
- Set latch low and output enable low.
Additional Notes
- If you see a ghosting effect, you can write a blank row after writing each row. I have done this after reading button presses so that the red artifacts from the button test patterns don’t appear on the display.
- I have added a delay after writing data to where I start reading the buttons for that row. Writing display data too fast can result in dimmed LEDs (although maybe you want that?). From my AI companion, for a target of 60Hz, you would work out the time to wait by doing (1 ÷ 60Hz) ÷ 6 rows = 0.001388 = 2777ms. I have used a value of 1388ms as I had a flickering effect with it any higher.