New Dice Widget

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;
  }
}
1 Like

I have set up a Git Repo on Bit Bucket

https://bitbucket.org/lsallen/blinks/

1 Like

Is it possible for a group of blinks to communicate there values and then workout if the roll is score less?

Yeah, this is an interesting distributed problem, but totally doable.

One way you could approach this is to have a Blink broadcast the lowest score it sees from direct neighbors. This will result in everyone sharing the lowest score. If the individual Blink is that score, it knows it is among the lowest (does not insure uniqueness).

This is a fun problem to work through, I believe that @Khaos created a fun dice game that did something similar.

Are you thinking something like this?

I will need to analise the code to see what it does and how it works but it could be a base of what I am looking for thank you Jon.