Go Down

Topic: Led Dice with Arduino (Read 2889 times) previous topic - next topic

Switchblade_46

Jun 14, 2010, 09:26 pm Last Edit: Jun 14, 2010, 09:37 pm by Switchblade_46 Reason: 1
Greetings to all Arduino forum members. My first real project with Arduino and my first topic in the forum.

I purchased the Arduino Duemilanove board from an authorized Arduino dealer and of course started with blinking led, playing tones, all the usual beginner stuff. I have been an electronics hobbyist for more than 20 years, but this is the first time I am into microcontrollers and programming.

When I saw a Led Die project on a website, I decided to make the Led Dice. It is indeed a variation of the original project, everything done twice. First, I got it running on the breadboard, later I assembled everything on a perforated PCB to finish it like a shield that would be pushed easily on the board.

It started like this:


And later like this:


First I decided to use the component legs as the connectors, but the PCB would not sit firmly on the board even if I cut the legs to length and also would not line up with the female connector on the board resulting in loose connections.


Then I went out and bought some connectors to replace the component legs. I had to solder the connectors on the coppered side of the PCB therefore I decided to strengthen them with two compound epoxy. It is now rock solid which will avoid any breakage of the soldered connectors.


And finally fabricated a dial from a piece of black plastic sheet to cover the resistors and enhance visibility of the leds.


After tweaking with the code, I tried to include some visual effects to make the dice seen more realistic. Left button tosses the dice, both dice roll twice and the left die stops. The second die continues to roll one more time as most of the time dice do not stop at the same time. When the second die stops, both of them are displayed until the left button pressed again. The code is still in progress, but it runs quite good so far. I will try to add more visual effects, play sound and flash when dice end up with double number etc.

I basically built this to play backgammon and when you are not happy with your luck or when your opponent begins to cry, the board (hence the luck) can be reset with the right button.

I will post the code and schematics (and a video hopefully) very soon.

Thanks for viewing and good luck to all!

My best,

SB46

Switchblade_46

#1
Jun 14, 2010, 10:58 pm Last Edit: Jun 14, 2010, 11:01 pm by Switchblade_46 Reason: 1
This is also my very first video created with Windows Movie Maker.

Please see my circuit in action. I hope you like it. Any comments are most welcomed.

http://www.youtube.com/watch?v=HasU0zA5W-0

Thanks!!!

frostin

LEDs for first project are best to start with!!! I did the knight rider demo etc when I got mine. Then I stepped up into dc motor control (built a spirograph arduino powered). Then I played with some its and bits sensors etc... Now I made my own led matrix, ds1307 board, which I have all hardware exept no time ATM to do it (learning to be a pilot). Once I get my bright undifused led clock done I am going to make a tv b gone or a remote for all 4 tvs...

Switchblade_46

Thanks Chris! Leds are fun to play with for sure.

Here is the circuit for Led Dice:


Best,
SB46

Odisej

Great job making two dices on one board!  :)

Some time ago I also made a dice, but in "single version", you can see the video here.


Regards

sidgug

Nice job and thanks for posting your schematic.

Are you able to share your code so I can learn how it's done?

Thanks again.

Odisej

If you are replying to me, it's all there, with english comments.  :)

Switchblade_46

#7
Jun 17, 2010, 08:09 pm Last Edit: Jun 17, 2010, 08:24 pm by Switchblade_46 Reason: 1
Thank you for your comments Gentlemen!

Here is the code for my Led Dice project. As already mentioned in my first post, it is my first experience with the Arduino language. Corrections, comments, criticisms all welcomed! I am eager to learn more.

Thanks!!!

Code: [Select]
/*
Led Dice with Arduino

Tosses a pair of die when a button is pressed.

Created 14 June 2010
By Switchblade_46

based on an Arduino Led die project by Davuzz11 at http://www.instructables.com/id/Arduino-Led-Dice/
*/

const int pinLeds1 = 4;  // assign group of leds1 to digital pin 4
const int pinLeds2 = 6;  // assign group of leds2 to digital pin 6
const int pinLeds3 = 7;  // assign group of leds3 to digital pin 7
const int pinLed4 = 5;   // assign led4 to digital pin 5
const int buttonPin = 3; // assign push-button digital pin 3
const int pinLeds5 = 8;  // assign group of leds5 to digital pin 8
const int pinLeds6 = 10; // assign group of leds6 to digital pin 10
const int pinLeds7 = 11; // assign group of leds7 to digital pin 11
const int pinLed8 = 9;   // assign led8 to digital pin 9
int buttonState;         // define pushbutton state
int ran1;                // define random number for die 1
int ran2;                // define random number for die 2
int time1 = 100;         // define time1 interval as 0.1 seconds
int time2 = 200;         // define time2 interval as 0.2 seconds
int time3 = 300;         // define time2 interval as 0.3 seconds

// The setup() method runs once, when the sketch starts
void setup ()
{
 pinMode (pinLeds1, OUTPUT); // declare pinLeds1 as output
 pinMode (pinLeds2, OUTPUT); // declare pinLeds2 as output
 pinMode (pinLeds3, OUTPUT); // declare pinLeds3 as output
 pinMode (pinLed4, OUTPUT);  // declare pinLed4 as output
 pinMode (buttonPin, INPUT); // declare buttonPin as input
 pinMode (pinLeds5, OUTPUT); // declare pinLeds5 as output
 pinMode (pinLeds6, OUTPUT); // declare pinLeds6 as output
 pinMode (pinLeds7, OUTPUT); // declare pinLeds7 as output
 pinMode (pinLed8, OUTPUT);  // declare pinLed8 as output
 randomSeed(analogRead(0));  // to avoid arduino to follow any pattern
}

// the loop() method runs over and over again, tosses the dice until you are bored or you are finished with it.
void loop()
{
 buttonState = digitalRead(buttonPin);
 if (buttonState == HIGH){ // checks state of pushbutton to start loop
   ran1 = random(1, 7); // a number between 1 to 6 is randomized for die 1
   ran2 = random(1, 7); // a number between 1 to 6 is randomized for die 2

 //dice are displayed until the button is pressed once again. the following code sets all leds off
 //otherwise the latest result of throw will still be displayed and the dice will not work.
 digitalWrite (pinLeds1, LOW);
 digitalWrite (pinLeds2, LOW);
 digitalWrite (pinLeds3, LOW);
 digitalWrite (pinLed4, LOW);
 digitalWrite (pinLeds5, LOW);
 digitalWrite (pinLeds6, LOW);
 digitalWrite (pinLeds7, LOW);
 digitalWrite (pinLed8, LOW);
 delay (time3);
 
 //now both dice are rolling
 digitalWrite (pinLed4, HIGH);
 digitalWrite (pinLed8, HIGH);
 delay (time1);
 digitalWrite (pinLed4, LOW);
 digitalWrite (pinLed8, LOW);
 delay (time1);
 digitalWrite (pinLed4, HIGH);
 digitalWrite (pinLed8, HIGH);
 digitalWrite (pinLeds3, HIGH);
 digitalWrite (pinLeds7, HIGH);
 delay (time1);
 digitalWrite (pinLed4, LOW);
 digitalWrite (pinLed8, LOW);
 digitalWrite (pinLeds3, LOW);
 digitalWrite (pinLeds7, LOW);
 delay (time1);
 digitalWrite (pinLed4, HIGH);
 digitalWrite (pinLed8, HIGH);
 digitalWrite (pinLeds2, HIGH);
 digitalWrite (pinLeds6, HIGH);
 delay (time1);
 digitalWrite (pinLed4, LOW);
 digitalWrite (pinLed8, LOW);
 digitalWrite (pinLeds2, LOW);
 digitalWrite (pinLeds6, LOW);
 delay (time1);
 digitalWrite (pinLed4, HIGH);
 digitalWrite (pinLed8, HIGH);
 digitalWrite (pinLeds1, HIGH);
 digitalWrite (pinLeds5, HIGH);
 delay (time1);
 digitalWrite (pinLed4, LOW);
 digitalWrite (pinLed8, LOW);
 digitalWrite (pinLeds1, LOW);
 digitalWrite (pinLeds5, LOW);
 delay (time1);
 
 //they are rolling once more
 digitalWrite (pinLed4, HIGH);
 digitalWrite (pinLed8, HIGH);
 delay (time1);
 digitalWrite (pinLed4, LOW);
 digitalWrite (pinLed8, LOW);
 delay (time1);
 digitalWrite (pinLed4, HIGH);
 digitalWrite (pinLed8, HIGH);
 digitalWrite (pinLeds3, HIGH);
 digitalWrite (pinLeds7, HIGH);
 delay (time1);
 digitalWrite (pinLed4, LOW);
 digitalWrite (pinLed8, LOW);
 digitalWrite (pinLeds3, LOW);
 digitalWrite (pinLeds7, LOW);
 delay (time1);
 digitalWrite (pinLed4, HIGH);
 digitalWrite (pinLed8, HIGH);
 digitalWrite (pinLeds2, HIGH);
 digitalWrite (pinLeds6, HIGH);
 delay (time1);
 digitalWrite (pinLed4, LOW);
 digitalWrite (pinLed8, LOW);
 digitalWrite (pinLeds2, LOW);
 digitalWrite (pinLeds6, LOW);
 delay (time1);
 digitalWrite (pinLed4, HIGH);
 digitalWrite (pinLed8, HIGH);
 digitalWrite (pinLeds1, HIGH);
 digitalWrite (pinLeds5, HIGH);
 delay (time1);
 digitalWrite (pinLed4, LOW);
 digitalWrite (pinLed8, LOW);
 digitalWrite (pinLeds1, LOW);
 digitalWrite (pinLeds5, LOW);
 delay (time1);
 
 //sets leds off on the first die just for viewing pleasure. It only delays for 0.1 secs before the last rolling of the second die.
 digitalWrite (pinLeds5, LOW);
 digitalWrite (pinLeds6, LOW);
 digitalWrite (pinLeds7, LOW);
 digitalWrite (pinLed8, LOW);
 delay (time1);
 
 // now arduino will toss the first die
   if (ran1 == 1){
     digitalWrite (pinLed8, HIGH); // turns on led8 if ran1 equals to 1
   }
   if (ran1 == 2){
     digitalWrite (pinLeds5, HIGH); // turns on leds5 if ran1 equals to 2
   }
   if (ran1 == 3){
     digitalWrite (pinLeds7, HIGH);
     digitalWrite (pinLed8, HIGH); // turns on leds7 and led8 if ran1 equals to 3
   }
   if (ran1 == 4){
     digitalWrite (pinLeds5, HIGH);
     digitalWrite (pinLeds7, HIGH); // turns on leds5 and leds7 if ran1 equals to 4
   }
   if (ran1 == 5){
     digitalWrite (pinLeds5, HIGH);
     digitalWrite (pinLeds7, HIGH);
     digitalWrite (pinLed8, HIGH); // turns on leds5 and leds7 and led8 if ran1 equals to 5
   }
   if (ran1 == 6){
     digitalWrite (pinLeds5, HIGH);
     digitalWrite (pinLeds6, HIGH);
     digitalWrite (pinLeds7, HIGH); // turns on leds5 and leds6 and leds7 if ran1 equals to 6
   }
 
 //second die still rolling as most of time dice do not stop at the same time
 digitalWrite (pinLed4, HIGH);
 delay (time1);
 digitalWrite (pinLed4, LOW);
 delay (time1);
 digitalWrite (pinLed4, HIGH);
 digitalWrite (pinLeds3, HIGH);
 delay (time1);
 digitalWrite (pinLed4, LOW);
 digitalWrite (pinLeds3, LOW);
 delay (time1);
 digitalWrite (pinLed4, HIGH);
 digitalWrite (pinLeds2, HIGH);
 delay (time1);
 digitalWrite (pinLed4, LOW);
 digitalWrite (pinLeds2, LOW);
 delay (time1);
 digitalWrite (pinLed4, HIGH);
 digitalWrite (pinLeds1, HIGH);
 delay (time1);
 digitalWrite (pinLed4, LOW);
 digitalWrite (pinLeds1, LOW);
 delay (time1);
 
 //sets leds off on the second die just for viewing pleasure. This time it puts a delay of 0.2 seconds to increase excitement.
 digitalWrite (pinLeds1, LOW);
 digitalWrite (pinLeds2, LOW);
 digitalWrite (pinLeds3, LOW);
 digitalWrite (pinLed4, LOW);
 delay (time2);
 
 // now arduino will toss the second die
  if (ran2 == 1){
     digitalWrite (pinLed4, HIGH); // turns on led4 if ran2 equals to 1
  }
  if (ran2 == 2){
     digitalWrite (pinLeds1, HIGH); // turns on leds1 if ran2 equals to 2
  }
  if (ran2 == 3){
     digitalWrite (pinLeds3, HIGH);
     digitalWrite (pinLed4, HIGH); // turns on leds3 and led4 if ran2 equals to 3
  }
   if (ran2 == 4){
     digitalWrite (pinLeds1, HIGH);
     digitalWrite (pinLeds3, HIGH); // turns on leds1 and leds3 if ran2 equals to 4
  }
   if (ran2 == 5){
     digitalWrite (pinLeds1, HIGH);
     digitalWrite (pinLeds3, HIGH);
     digitalWrite (pinLed4, HIGH); // turns on leds1 and leds3 and led4 if ran2 equals to 5
  }
  if (ran2 == 6){
     digitalWrite (pinLeds1, HIGH);
     digitalWrite (pinLeds2, HIGH);
     digitalWrite (pinLeds3, HIGH); // turns on leds1 and leds2 and leds3 if ran2 equals to 6
  }  
     
 }
}


Go Up