Simulating dice throwing on ATtiny


🔧 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

📡Broadcast the signal — amplify the connection.

Leave a Reply