กลับไปหน้ารวมไฟล์
dice-of-leds-4333f3-en.md

The COVID - 19 lock-down is really a bummer for us all so, while the world is digitalizing why can't the old fashioned dice do too? So here we go..

This project works with a push of a button (Literally XD). It uses a random generator to generate a random number from 1 to 6.

Hardware Setup and Initialization

This DIY Electronic Dice uses six LEDs representing the faces of a standard die. Each LED is connected to a specific digital pin (2 through 7) on the Arduino Uno, while a momentary push button is used as the trigger on pin 11.

Programming the Randomness

The core of the logic resides in the random(min, max) function. In Arduino, random(1, 7) generates a pseudo-random integer between 1 and 6. To ensure the sequence isn't predictable after a reset, it is best practice to seed the generator using randomSeed(analogRead(0)) if you have an unconnected analog pin.

Code Structure

We define the pins and track the button's state:

int ledPins[] = {2, 3, 4, 5, 6, 7};
int button = 11;
int buttonState = 0;

Game Flow

  1. Input Detection: The Arduino constantly monitors the button state using digitalRead(button).
  2. Roll Trigger: If the button is pressed (buttonState == 1), the code calls the random function.
  3. LED Output: Depending on the resulting number (1-6), specific LEDs are turned HIGH. For example, a result of '3' turns on three LEDs while keeping the others LOW.
  4. Display Lock: A delay(10000) is implemented to keep the result visible before resetting for the next turn.

Creative Customization

To make the dice more authentic, you can arrange the LEDs in a traditional 3x3 grid layout (using 7 LEDs total to include the center dot). You can also add a "rolling" animation where the LEDs blink rapidly for a few seconds before settling on the final result, adding to the suspense of the game!

ข้อมูล Frontmatter ดั้งเดิม

title: "Dice of Leds"
description: "The most easiest way available to make an LED dice controlled by a push button."
author: "thegifat"
category: ""
tags:
  - "lights"
  - "recreation"
  - "games"
views: 1094
likes: 1
price: 99
difficulty: "Easy"
components:
  - "1x 9V Battery Clip"
  - "6x LED (generic)"
  - "1x 9V battery (generic)"
  - "1x Pushbutton Switch, Momentary"
  - "1x Arduino UNO"
tools: []
apps:
  - "1x Arduino IDE"
downloadableFiles:
  - "https://projects.arduinocontent.cc/d6418e43-3636-40c0-a2a9-7ee4bf151422.ino"
documentationLinks: []
passwordHash: "8d7fc905a5b2a71648cb447d34aca8ef0ca50d1fe92187c14afdaf3f5f86d435"
encryptedPayload: "U2FsdGVkX19Rmk2q7zAoN3/UoqCXYzZwFqG1sp8Pk+V/r6NIwwLbz5RqVQfI3zRdGgTyCNuus+kL8pyPWARcZFRmEvcSBtf5gd9gflm+0ys="
seoDescription: "Create an LED dice controlled by a Push Button using the simplest method available. Ideal for beginners."
videoLinks: []
heroImage: "https://cdn.jsdelivr.net/gh/bigboxthailand/arduino-assets@main/images/projects/dice-of-leds-4333f3_cover.jpg"
lang: "en"