Project tutorial

# Special Functions For The Kid's Cube © GPL3+

The Arduino dice of my previous project are perfect for kids. But it's even better if you add some special functions.

• 15 views
• 0 respects

## Components and supplies

 Arduino UNO & Genuino UNO
×1
 Arduino Nano R3
×1

## Apps and online services

 Arduino IDE

In a round of Ludo or Parcheese, nothing is better than winning, or at least having lots of 6s and bringing all the pieces on the field.

With a normal dice you need a lot of luck. Children can help there luck with these versions of the Arduino program of my Cube for Kids.

### Version 1

If you got the dice for your own, you could simply increase the probability and make a 6 occur more frequently.

This works in source code with an additional condition.

``````zufall=zufall%6; //result is number 0..5
if zufall<>5 {zufall=millis()%6;} //dice again if no 6!
``````

But that quickly comes up and it's possible that all other players throw the electronic dice. Who wants that others often have a 6?

### Version 2

Better is an inconspicuous variant: During dicing (= key pressed), the holding time of the key is measured. If this is between 3 and 4 seconds, the throw becomes a 6.

``````spezial=millis()-spezial;
if ((spezial>3000) and (spezial<4000)) {
zufall=5; //6!
}
``````

### Version 3

That's quite good, but could be noticed over time. Less noticeable, if only the probability of a 6 in the interval of 2..3 seconds is increased.

It looks like this:

``````spezial=millis()-spezial;
if ((spezial>2000) and (spezial<3000)) {
if (zufall!=5) {zufall=millis()%6;} //dice again, if no 6!
}
``````

### Pimped cube

The cube animation is best suited for that. This change makes it easy to set even more effects.

``````// LED order
// 1   2
// 3 7 4
// 5   6
int wuerfelBild[8][7]=
{{0,0,0,0,0,0,0}, //0 = all LED's off
{0,0,0,0,0,0,1}, //1
{0,1,0,0,1,0,0}, //2
{1,0,0,0,0,1,1}, //3
{1,1,0,0,1,1,0}, //4
{1,1,0,0,1,1,1}, //5
{1,1,1,1,1,1,0}, //6
{1,1,1,1,1,1,1}}; //7 = all LED's on
int lauflichtmax=6;
int lauflicht[6]=     {  1,  7,  6,  2,  7,  5}; //LED number
int lauflichtpause[6]={ 60,100,180,180,100, 60}; //time in ms
``````

Or something like a Knight-Rider effect:

`````` int lauflichtmax=6;
int lauflicht[6]=     {  3,  7,  4,  4,  7,  3}; // sequence of LED's
int lauflichtpause[6]={100,180,100,100,180,100}; // time in ms
``````

Have fun with inconspicuous cheating and pimples.

PS: Wenn Sie das Projekt in Deutsch lesen möchten, schauen Sie in meinen Blog auf tangielskyblog.wordpress.com.

## Code

##### wuerfel2_v3.inoArduino
```// Program: LED Dice version 3

// setup the pins
// pin number of the first LED
int PinErsteLED=2;

// pin number of the button
int PinTaster=9;

// LED order
// 1   2
// 3 7 4
// 5   6
int wuerfelBild[8][7]=
{{0,0,0,0,0,0,0}, //0 = all LED's off
{0,0,0,0,0,0,1}, //1
{0,1,0,0,1,0,0}, //2
{1,0,0,0,0,1,1}, //3
{1,1,0,0,1,1,0}, //4
{1,1,0,0,1,1,1}, //5
{1,1,1,1,1,1,0}, //6
{1,1,1,1,1,1,1}}; //7 = all LED's on

int lauflichtmax=6;
int lauflicht[6]=     {  1,  7,  6,  2,  7,  5}; //LED number
int lauflichtpause[6]={ 60,100,180,180,100, 60}; //time in ms

void setup() {

// define all pins as output
for (int i=PinErsteLED;i<=PinErsteLED+6;++i)
pinMode(i,OUTPUT);

// pin of the button
pinMode(PinTaster,INPUT);
}

// function to show the result
void ZeigeZahl(int zahl) {
for (int i=0;i<=6;++i)
digitalWrite(i+PinErsteLED,wuerfelBild[zahl][i]?HIGH:LOW);
}

void loop() {
//declare variables
int i,j,zufall;
unsigned long spezial;

ZeigeZahl(7); //all LED's on
delay(1000);  // wait 1 second
// start animation
i=0;
do {
i=i+1;
if (i>6) {i=1;}
delay(500);
ZeigeZahl(i); //show number
} while (digitalRead(PinTaster)==HIGH); //wait til key is pressed

// start dicing
do {
//setup
zufall=0;
i=0;
spezial=millis();
do {
zufall=zufall+1; //used for random number
i=i+1;
if (i>=lauflichtmax) {i=0;} //if i is lauflichtmax, then set i to 0, so i is in 0..6
delay(lauflichtpause[i]); //wait

ZeigeZahl(0); // all LED's off
digitalWrite(PinErsteLED+lauflicht[i]-1,HIGH);

} while (digitalRead(PinTaster)==LOW); //repeat until the button is releashed

zufall=zufall%6; //result is number 0..5
spezial=millis()-spezial;
if ((spezial>2000) and (spezial<3000)) {
if (zufall!=5) {zufall=millis()%6;} //dice again, if no 6!
}
ZeigeZahl(zufall+1); //show number

while (digitalRead(PinTaster)==HIGH); //wait til next keypress
} while (1==1); //repeat endless
}

```

• 3 projects
• 0 followers

#### Published on

December 9, 2017
See similar projects
you might like

#### Alexa Controlled LEDs Through Raspberry Pi

Project tutorial by vincent wong

• 748 views
• 5 respects

• 1,529 views
• 4 respects

#### Arduino Indoor Garden

Project tutorial by MEGA DAS

• 12,887 views
• 43 respects

Project showcase by Projecter

• 3,143 views
• 4 respects

#### SERENA: Alarm Control Panel

Project tutorial by Michael Marinis

• 4,619 views