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