PCBX
Published

Rolling Virtual Dice: A Look at Dice Simulators

Discover the thrill of chance with dice simulators! Experience endless gaming possibilities and ignite your love for probability.

BeginnerProtip147

Things used in this project

Story

Read more

Schematics

dice_6RjO9A4mgc.png

Code

Untitled file

Arduino
#include <LiquidCrystal.h>

int segmentPins[] = {2, 3, 4, 5, 6, 7, 8};
int buttonPin = A0;

byte numbers[10] = {
  0x3F, // 0
  0x06, // 1
  0x5B, // 2
  0x4F, // 3
  0x66, // 4
  0x6D, // 5
  0x7D, // 6
  0x07, // 7
  0x7F, // 8
  0x6F  // 9
};

int diceNumber = 0;

void setup() {
    for (int i = 0; i < 7; i++) {
        pinMode(segmentPins[i], OUTPUT);
    }
    pinMode(buttonPin, INPUT);
}

void loop() {
    if (digitalRead(buttonPin) == HIGH) {
        displayNumber(random(1,7));
    }
}

void displayNumber(int num) {
    for (int i = 0; i < 7; i++)
        digitalWrite(segmentPins[i], numbers[num] & (1 << i));
    delay(1000);
}

Credits

PCBX
33 projects • 9 followers
Customer Success: Your one-stop solution for PCB and PCBA services, plus component sourcing. Enjoy FREE online simulation and EDA.
Contact

Comments

Please log in or sign up to comment.