The Great Cogsworth Gambling Den
The steam-powered gears of Cogsworth City never stop turning, and neither does its underground gambling scene. Deep beneath the brass-plated streets, in the shadow of the great clockwork towers, lies Madame Voltage's infamous gaming parlor. The air thick with copper dust and the electric tang of sparking circuits, desperate inventors and clockwork engineers gather around flickering tables, wagering their last copper coins on games of chance.
Tonight, the stakes are higher than usual. Word has spread through the mechanical workshops that someone has been cheating with loaded dice, and tensions are running hot as a Tesla coil. The problem? These aren't ordinary dice carved from bone or wood. In Cogsworth City, even the games of chance run on electricity and precision engineering.
Madame Voltage slides a peculiar contraption across the felt table toward you. Six glowing orbs arranged in a line, connected by thin copper wires to a brass button mechanism. "This, my dear inventor, is how we settle disputes in my establishment," she purrs, her voice crackling like static electricity. "No weighted sides, no clever tricks. Just pure randomness, generated by the chaos of electrons themselves."
The device hums softly, its internal mechanisms ready to transform electrical noise into fair play. One press of that button, and the laws of probability will decide your fate. Will you walk away with pockets full of coin, or will you leave with nothing but the knowledge of how to build the most honest dice in all of Cogsworth City? The choice, as they say, is entirely random.
What You'll Master
When you finish building this electronic dice, you'll be able to:
- Create a random number generator that produces truly unpredictable results
- Control multiple LEDs in sequence to display numerical values
- Build anticipation with animated LED patterns before revealing results
- Use button input to trigger complex sequences of events
- Understand how computers generate randomness from electrical noise
- Program conditional logic that responds to different numerical outcomes
Understanding Random Numbers
Here's something that might blow your mind: computers are terrible at being random. Think about it. A computer follows instructions exactly, step by step, with perfect precision. Ask it to add 2 + 2, and it will give you 4 every single time. This predictability is normally what we want, but when you're trying to simulate rolling dice, predictability is the enemy.
So how do we make a perfectly logical machine behave randomly? We cheat. We tap into the one thing that's genuinely chaotic in the electronic world: electrical noise. Every wire, every component, every tiny imperfection in the circuit creates microscopic electrical fluctuations. These fluctuations are completely unpredictable, like trying to predict exactly which way a leaf will tumble in a windstorm.
Your HERO Board has a special trick up its sleeve. It can read these electrical fluctuations from an unconnected pin and use them as a "seed" for generating random numbers. Think of it like shaking a snow globe before making a decision. The random electrical noise provides just enough chaos to make each dice roll genuinely unpredictable.
But generating the random number is only half the battle. The real magic happens when we translate that number into something visual. Instead of showing "3" on a tiny screen, we light up exactly three LEDs in sequence. The human brain instantly recognizes the pattern, just like counting dots on a traditional die. It's the same principle casinos use: make the outcome immediately obvious, emotionally engaging, and impossible to dispute.
Wiring Your Electronic Dice
This project requires 6 LEDs arranged in a line to represent dice values 1-6, plus one button to trigger the dice roll. Here's why each connection matters:
- LEDs to pins 2-7: We use consecutive pins because it makes the code cleaner when we want to loop through all LEDs. Each LED needs a 220-ohm resistor to limit current and prevent burnout.
- LED cathodes to ground: This completes the electrical circuit. Without this connection, no current flows and no light appears.
- Button to pin 12: We chose pin 12 because it's far from the LED pins, reducing the chance of electrical interference affecting our dice rolls.
- Button pull-down resistor: Connect a 10k resistor between the button and ground. This prevents false readings when the button isn't pressed.
- Button power connection: Connect one side of the button to 5V so pressing it sends a HIGH signal to pin 12.