Pages: [1]   Go Down
Author Topic: It Woiks!  (Read 127 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 32
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I just got my first Arduino project -- an electronic dice roller -- working.  It's pretty simple -- maybe a better term would be infantile -- but for someone with no experience in this area it's a bit of a kick.

Attached are some photos (inside and out) and a schematic, and the code is below.

Code:
/* Electronic Dice Roller, v. 1.0

By Robert Rothman, 8/16/14 */

#define buttonPin 2 /* Connect roll button to pin2 */
#define bigJuliePin 3 /* Connect Big Julie switch to pin 3 */
#define die0Latch 4 /* Connect latch pin for shift register 0 to pin 4 */
#define die0Clock 5 /* Connect clock pin for shift register 0 to pin 5 */
#define die0Data 6 /* Connect data pin for shift register 0 to pin 6 */
#define die1Latch 7 /* Connect latch pin for shift register 1 to pin 7 */
#define die1Clock 8 /* Connect clock pin for shift register 1 to pin 8 */
#define die1Data 9 /* Connect data pin for shift register 1 to pin 9 */
boolean rolled [] = {false, false};


void setup()
{
  pinMode (buttonPin, INPUT);
  pinMode (die0Latch, OUTPUT);
  pinMode (die0Clock, OUTPUT);
  pinMode (die0Data, OUTPUT);
  pinMode (die1Latch, OUTPUT);
  pinMode (die1Clock, OUTPUT);
  pinMode (die1Data, OUTPUT);
  pinMode (bigJuliePin, INPUT);
  randomSeed (analogRead(0));
  Serial.begin(9600);


void loop()
{
  boolean rollButtonPressed = digitalRead(buttonPin);
  boolean bigJulieModeOff = digitalRead (bigJuliePin);
  int die;
  int dieScore = 0;
  int pips[2];
  if (rollButtonPressed) /* Wait until roll button is pressed */
  {
    Serial.println("Button Pressed");
    for (die = 0; die <2; die ++) /* All this happens twice, once for each die */
      {
        rolled[die] = true;
        if (rolled[die])
        {
          if(bigJulieModeOff) /* test to see if Big Julie mode is OFF (i.e., switch is turned ON) */
            {
             dieScore = rollDie();
             Serial.println(dieScore);
             pips[die] = figurePips(dieScore - 1);
            }
          else /* if Big Julie Mode is on, you have to remember where da spots formerly was */
          {
          pips[die] = 0;
          }
          showTheRoll(pips[die], die);
          }     
     }
  }
}
 
int rollDie()
{
  int number = random(1,7);
  return number;

}

int figurePips(int diescore)
{
  int pipsLocation[] = {B00001000, B01000001, B00101010, B01100011, B01101011, B01110111}; /* These represent the physical locations of the pips on each side of a standard die.  Note that although there are only six possible numbers, there are seven possible locations for each pip. */
  Serial.println(pipsLocation[diescore-1]);
  return pipsLocation[diescore];
   
 
}

void showTheRoll(int pipsOn, int dieNumber) /* sends info to the two shift registers, one for each die, which control the LEDs */
{
  if (dieNumber == 0)
    {
      digitalWrite (die0Latch, LOW);
      shiftOut (die0Data, die0Clock, MSBFIRST, pipsOn);
      digitalWrite (die0Latch, HIGH);
      rolled[0]=false;
    }
  else
    { 
  digitalWrite (die1Latch, LOW);
  shiftOut (die1Data, die1Clock, MSBFIRST, pipsOn); 
  digitalWrite (die1Latch, HIGH);
  rolled[1]=false; 
    }
   
}


Rob Rothman


* Picture 3.jpg (283.44 KB, 1600x1200 - viewed 14 times.)

* Picture 4.jpg (418.8 KB, 1600x1200 - viewed 11 times.)

* Picture 5.jpg (471 KB, 1600x1200 - viewed 16 times.)
* Dice Roller Schematic.pdf (58.82 KB - downloaded 7 times.)
Logged

Copenhagen, Denmark
Offline Offline
Edison Member
*
Karma: 33
Posts: 1226
Have you testrun your INO file today?
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Looking at your previous posts, it has been an exciting journey for you - and the finished project is noce. There is no such thing as "simple" - your project may be too advanced for others on this forum. If you as an indvidual feel proud of it, then it is indeed a good project.

Even so, I sincerley think it is a good project. You completed it, nice looking box an all. Now, the litmus test: Is it being used when you play a board game that requires a die or pair of dice smiley ?
Logged

Offline Offline
Faraday Member
**
Karma: 100
Posts: 6055
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Nice job !
I think I'll make one to take to Vegas.... smiley-mr-green
Logged

Arduino UNOs, Pro-Minis, ATMega328, ATtiny85, LCDs, MCP4162, keypads,
DS18B20s,74c922,nRF24L01, RS232, SD card, RC fixed wing, quadcopter

Pages: [1]   Go Up
Jump to: