π§ GOAL:
- Use only 3 output pins to simulate dice rolls (1β6)
- Drive 7 LEDs arranged like a classic die
- Show different patterns using clever pin logic
- One button triggers a random roll
π§ HOW DOES IT WORK?
Instead of controlling each LED separately, we treat each number (1β6) as a predefined pattern, and reuse the same pins to display different combinations. Each time the button is pressed, a random number is generated, and the 3 output pins are set to match that numberβs LED layout.
𧩠SCHEMATIC OVERVIEW
- PB0, PB1, PB2 β connected to 3 LED combinations
- LEDs are wired cleverly so you can light up different patterns by combining pins
- Button connected to PB4 with 10kΞ© pull-up resistor
- Bypass 0.1 Β΅F capacitor between Vcc and GND for power noise filtering β‘
- 10kΞ© Pull-Up Resistor on RESET. Prevents false resets if RESET is not disabled via fuse bits
π§° Tinkercad CODE (3-pin LED logic + button)
// C++ code
//
int number = 0;
void setup()
{
pinMode(A2, INPUT);
pinMode(0, OUTPUT);
pinMode(1, OUTPUT);
pinMode(2, OUTPUT);
number = 0;
}
void loop()
{
if (analogRead(A2) == 0) {
number = random(1, 6 + 1);
if (number == 1) {
digitalWrite(0, HIGH);
digitalWrite(1, LOW);
digitalWrite(2, LOW);
}
if (number == 2) {
digitalWrite(0, LOW);
digitalWrite(1, HIGH);
digitalWrite(2, LOW);
}
if (number == 3) {
digitalWrite(0, HIGH);
digitalWrite(1, HIGH);
digitalWrite(2, LOW);
}
if (number == 4) {
digitalWrite(0, LOW);
digitalWrite(1, LOW);
digitalWrite(2, HIGH);
}
if (number == 5) {
digitalWrite(0, HIGH);
digitalWrite(1, LOW);
digitalWrite(2, HIGH);
}
if (number == 6) {
digitalWrite(0, LOW);
digitalWrite(1, HIGH);
digitalWrite(2, HIGH);
}
}
delay(10); // Delay a little bit to improve simulation performance
}
π HOW TO CONNECT THE LEDS?
- Each LED (or LED pair) lights up only when certain pins are HIGH
- For example, some LEDs might be shared between pins with diodes or resistors, or wired in a simple multiplexed triangle form
- Limit the current with resistor to prevent the LED from burning out.
π‘ EXTRAS YOU CAN ADD
- β¨ Real dice animation (fast random blinking)
- π Buzzer click sound
- π€ ATtiny power-down when idle
- π¨οΈ Custom 3D-printed cube with translucent windows for LEDs