# How do I make an electronic dice

Now, for a change, a project that can be used. In this chapter we will construct an electronic cube. You can use this for any dice game, like Kniffel or Mensch ärgere dich nicht. To do this, we press a button. Then the LEDs should light up in a mess. After a while the number of the dice will be displayed.

• 7 x ohmic resistor (220 Ohm)

The green lines are for the first three LEDs, the orange line for the fourth and the purple lines for the last 3 LEDs.

int led [] = {13,12,11,10,9,8,7}; // Variables for the LEDs

int augen   = {{0,0,0,1,0,0,0}, // dice number 1

{1,0,0,0,0,0,1}, // dice number 2

{1,0,0,1,0,0,1}, // dice number 3

{1,0,1,0,1,0,1}, // dice number 4

{1,0,1,1,1,0,1}, // die number 5

{1,1,1,0,1,1,1}}; // dice number 6

int button = 4; // Variable for the button

int buttonStatus; // Status query of the button

voidsetup () {

for (int index = 0; index <= 6; index ++) //

{                                                           //

//

pinMode (led [index], OUTPUT); // Define LEDs as output

//

}                                                           //

pinMode (button, INPUT); // push button as input

// define

digitalWrite (button, HIGH); // pull-up resistor

// activate

}

voidloop () {

buttonStatus = digitalRead (button); // Query the status of the button

if (buttonStatus == LOW) // If button is pressed

{

for (int index1 = 0; index1 <= 50; index1 ++) // delivery 51 random numbers

{

int random = random (0.6); // give a random number

// between 1 and 6

for (int index2 = 0; index2 <= 6; index2 ++)

{

digitalWrite (led [index2], eyes [random] [index2]);

}

delay (50);

}

} // the 51st number is the

// number rolled

}

You can also download the sketch here.

int random = random (0.6); // give a random number

// between 1 and 6

the random method specifies a random number as described above. To do this, you give the method the lowest and the highest number as parameters.

If you miss anything here, have better approaches or something is not clear to you, don't hesitate to leave a comment.