Arduino Dice Challenge


The Project

This week my challenge was to create a random number generator, with each LED representing the dots of a dice.  This task was rather daunting as I didn't quite understand how random generators worked going in to this project.

The Code 

In the initial setup, I labeled the individual LEDS connected them to a port.  I found on the Arduino Help Boards that index++ means increase by increments of one (which I didn't understand last week) and added that to the random number generator.  I then set my random number code to represent as dice patterns so for example, if the random number = 5,  I set a pattern of LEDs making the dice "5" pattern (with the four dots at four corners and one dot in the middle) to be HIGH with the rest of the LEDS set to LOW.  I used the "else if" function and the delay to 2000 because when I initially set it to 1000, the dice blinked so quickly that it was hard for me to tell if it was truly random, but when I slowed it down and watched the function on a loop to ensure the numbers were actually random.

 




Picture of the Circuit 



Diagram 



Youtube Video



Final Reflection

As usual, most of my issues in getting the dice pattern LEDS to work, involved a faulty connection with the circuit itself, specifically the resistors.  I also grabbed a stronger resister than the others (330 ohms) and then realized my mistake when it made the other LED duller than the rest.  When I put my random function in (randomNumber = random(1,7);), I initially put "random(1,6); and then realized the code runs one number under what you put so I could only generate 5 dice patterns unless I changed it to "random(1,7)" instead of 6.

Possible Extensions

I could see how t his code could be used to spell custom messages on a marquee board or gambling machines in Vegas, with perhaps economic predictions or simulations.  


Graph of Random "Dice Rolls"



Comments

Popular posts from this blog

Week 5 Piezzo Buzzer Arduino Project