Introduction: Arduino LED Dice Game!

This game is just a simple two player dice game! The objective is to be the first player to get 1.

Step 1: Step 1: Setting Up Materials

Here is a list of materials that you will need to assemble this project.

Arduino

7x LED

7x 220Ω or 330Ω Resistor (red red brown or orange orange brown)

Push Button

Breadboard

Wires

Active Buzzer

Dot Matrix Parts (Optional for aesthetics)

8*8 dot-matrix

8x 220Ω Resistor (red red brown)

2x 74HC595

USB Cable

Step 2: Step 2: Setting Up Dice Layout

*Make sure you put a wire from the 5V pin on the arduino to the RED positive rail on the breadboard and the GND pin to the BLUE positive rail on the breadboard.*

First, you will want to set up the LED's in a dice layout like I have done in the picture. After that, you will put a resistor on each of the short pins on the LED's. Then connect longer wires from the long pins of the LED to the digital pins on the Arduino. Personally, I put them in random order from pins 2-7 & 9. Then, to install the button, you will want to put it on any free space on the breadboard like I have done and connect it the way I have connected it. Connect the blue wire to pin 8. For the buzzer, simply find another free space and wire it as I have done. The yellow wire connects to the ground rail and the red wire connects to pin 11 on the Arduino. Congrats, you are done the Dice part of the project. Move onto the next step for the optional dot matrix part of the project.

Step 3: Step 3: 8x8 Dot Matrix

In this step, you will create a small dot matrix to spam a bunch of numbers when you win (get a 1 on the dice).

You will follow the diagram to make sure you wire it properly. Make sure that the part of the matrix with the numbers is on the bottom when you are wiring it. Replace the pins it tells you to put in the Arduino with,

Pin 9 - 10

Pin 11 - 13

Pin 12 - 12

Step 4: Step 4: Code

Use the following code below to finish your project!

Code:

const int latchPin = 10;//Pin connected to ST_CP of 74HC595
const int clockPin = 12;//Pin connected to SH_CP of 74HC595 const int dataPin = 13; //Pin connected to DS of 74HC595 int Led1 = 9; int Led2 = 2; int Led3 = 3; int Led4 = 4; int Led5 = 5; int Led6 = 6; int Led7 = 7; int ran; int buttonPin = 8; int buttonState = 0; int buzzer = 11; int data[] = { /*0xFF,0xC1,0xBE,0xBE,0xBE,0xC1,0xFF,0xFF,/*"0",0*/ /*0xFF,0xDF,0xDF,0x80,0xFF,0xFF,0xFF,0xFF,/*"1",1*/ 0xFF,0xDC,0xBC,0xBA,0xB6,0xCE,0xFF,0xFF,/*"2",2*/ /*0xFF,0xDD,0xBE,0xB6,0xB6,0xC9,0xFF,0xFF,/*"3",3*/ /*0xFB,0xF3,0xEB,0xDB,0x80,0xFB,0xFF,0xFF,/*"4",4*/ /*0xFF,0x8D,0xAE,0xAE,0xAE,0xB1,0xFF,0xFF,/*"5",5*/ /*0xFF,0xC1,0x96,0xB6,0xB6,0xD9,0xFF,0xFF,/*"6",6*/ }; void setup() { pinMode (Led1, OUTPUT); pinMode (Led2, OUTPUT); pinMode (Led3, OUTPUT); pinMode (Led4, OUTPUT); pinMode (Led5, OUTPUT); pinMode (Led6, OUTPUT); pinMode (Led7, OUTPUT); pinMode (buttonPin, INPUT); pinMode(latchPin,OUTPUT); pinMode(clockPin,OUTPUT); pinMode(dataPin,OUTPUT); pinMode(buzzer, OUTPUT); Serial.begin(9600); }

void loop() { buttonState = digitalRead(buttonPin); Serial.println(buttonState); if (buttonState == HIGH){ ran = random(1,7); roll(); delay(500); if (ran == 1){ digitalWrite (Led2, HIGH); analogWrite (buzzer,100); delay(100); analogWrite (buzzer, 0); delay(100); analogWrite (buzzer,100); delay(100); analogWrite (buzzer, 0); delay(100); analogWrite (buzzer,100); delay(100); analogWrite (buzzer, 0); for(int n = 0; n < 200 ; n++) { for(int t = 0;t < 10;t ++)//Show repeated 10 times { int dat = 0x01; for(int num = n; num < n+8; num++) { shiftOut(dataPin,clockPin,MSBFIRST,~data[num]);//control ROW of dot matrix shiftOut(dataPin,clockPin,MSBFIRST,~dat); //control COL of dot matrix //return the latch pin high to signal chip that it //no longer needs to listen for information digitalWrite(latchPin,HIGH); //pull the latchPin to save the data //delay(1); //wait for a microsecond digitalWrite(latchPin,LOW); //ground latchPin and hold low for as long as you are transmitting dat = dat<<1; } } } delay(1000); } else if (ran == 2){ digitalWrite (Led1, HIGH); digitalWrite (Led7, HIGH); delay(1000); } else if (ran == 3){ digitalWrite (Led1, HIGH); digitalWrite (Led7, HIGH); digitalWrite (Led4, HIGH); delay(1000); } else if (ran == 4){ digitalWrite (Led1, HIGH); digitalWrite (Led7, HIGH); digitalWrite (Led3, HIGH); digitalWrite (Led5, HIGH); delay(1000); } else if (ran == 5){ digitalWrite (Led1, HIGH); digitalWrite (Led7, HIGH); digitalWrite (Led3, HIGH); digitalWrite (Led5, HIGH); digitalWrite (Led4, HIGH); delay(1000); } else if (ran == 6){ digitalWrite (Led1, HIGH); digitalWrite (Led2, HIGH); digitalWrite (Led3, HIGH); digitalWrite (Led5, HIGH); digitalWrite (Led7, HIGH); delay(1000); } else if (ran == 7){ digitalWrite (Led1, HIGH); digitalWrite (Led2, HIGH); digitalWrite (Led3, HIGH); digitalWrite (Led4, HIGH); digitalWrite (Led5, HIGH); digitalWrite (Led6, HIGH); digitalWrite (Led7, HIGH); } } else { digitalWrite (Led1, LOW); digitalWrite (Led2, LOW); digitalWrite (Led3, LOW); digitalWrite (Led4, LOW); digitalWrite (Led5, LOW); digitalWrite (Led7, LOW); }

} void roll(){ digitalWrite (Led1, HIGH); digitalWrite (Led2, HIGH); digitalWrite (Led3, HIGH); digitalWrite (Led4, HIGH); digitalWrite (Led5, HIGH); digitalWrite (Led6, HIGH); digitalWrite (Led7, HIGH);

delay(50);

digitalWrite (Led1, LOW); digitalWrite (Led2, LOW); digitalWrite (Led3, LOW); digitalWrite (Led4, LOW); digitalWrite (Led5, LOW); digitalWrite (Led6, LOW); digitalWrite (Led7, LOW);

delay(50);

digitalWrite (Led1, HIGH); digitalWrite (Led2, HIGH); digitalWrite (Led3, HIGH); digitalWrite (Led4, HIGH); digitalWrite (Led5, HIGH); digitalWrite (Led6, HIGH); digitalWrite (Led7, HIGH);

delay(50);

digitalWrite (Led1, LOW); digitalWrite (Led2, LOW); digitalWrite (Led3, LOW); digitalWrite (Led4, LOW); digitalWrite (Led5, LOW); digitalWrite (Led6, LOW); digitalWrite (Led7, LOW);

delay(50);

digitalWrite (Led1, HIGH); digitalWrite (Led2, HIGH); digitalWrite (Led3, HIGH); digitalWrite (Led4, HIGH); digitalWrite (Led5, HIGH); digitalWrite (Led6, HIGH); digitalWrite (Led7, HIGH);

delay(50);

digitalWrite (Led1, LOW); digitalWrite (Led2, LOW); digitalWrite (Led3, LOW); digitalWrite (Led4, LOW); digitalWrite (Led5, LOW); digitalWrite (Led6, LOW); digitalWrite (Led7, LOW); }