The design is quite simple – ports PORTB and PORTD have internal pull-up resistors, so we’ll enable those and use them for the digital inputs. Each slot in the tray has four input pins (so we can work out which way around the cube has been placed) plus one serial data line. The input pins need to be pulled high/low when a cube is not present, so slot 1 uses PORTD.0-3, slot 2 uses PORTd.4-7, slot 3 uses PORTB.0-3 and slot 4 uses PORTB.4-7. The serial data lines have been put onto any four free input pins (PORTA.2-5) and any remaining (output) pins are used to illuminate some LEDs.
When we start reading a cube, we’ll turn a red LED on.
When a cube has been read (and the data validated as correct) the red LED goes out and a green LED is lit.
This way, all empty slots have no light and if any cube fails a read, a red LED will indicate which cube(s) have caused the error. Cubes that have been successfully recognised will light the LED green. We may even use bi-colour LEDs instead of two separate components – reducing component count and allowing a yellow colour to be achieved if necessary for future development.