I have started to build a dice only widget but can not test it just yet this is because I am without blinks yet, please feel free to play with my code it is released under the GPL version 2.0. Please credit me and post revisions to the code below:
byte roll;
byte orientFace;
void setup() {
// put your setup code here, to run once:
randomize(); // setup the random number generator
}
void loop() {
// if button pressed generate a new random number
if (buttonPressed())
{
roll = random(6)+1; // generate a random number
orientFace = roll -1;
}
setColor(OFF); // turns all 6 RGB LEDs off
// checks which number was rolled then displays the results on the LEDs
switch (roll) {
case 1:
setColorOnFace(RED, orientFace);
break;
case 2:
setColorOnFace(ORANGE, orientFace);
setColorOnFace(ORANGE, (orientFace + 3) % 6);
break;
case 3:
setColorOnFace(YELLOW, orientFace);
setColorOnFace(YELLOW, (orientFace + 2) % 6);
setColorOnFace(YELLOW, (orientFace + 4) % 6);
break;
case 4:
setColor(GREEN);
setColorOnFace(OFF, orientFace);
setColorOnFace(OFF, (orientFace + 3) % 6);
break;
case 5:
setColor(BLUE);
setColorOnFace(OFF, orientFace);
break;
case 6:
setColor(MAGENTA);
break;
}
}