Electronic Dice

February 27th, 2011 § 0 comments

Got a chance to introduce Arduino to the boy scout at YCIS. It was a fun afternoon working with the boys and the parents. Here are more on the design of the electronic dice. Look forward to seeing the boys completing the system next week.

The tool used to design the dice is Fritzing. It’s an open source design program for interactive electronics. The functionalities of the dice is pretty straight forward: when the button is press, the LEDs start to flash and on the release of the button, one of the LED is randomly picked.

Untitled

Untitled

Arduino is used to drive the dice logics. Arduino is a popular open source microcontroller for building interactive electronics. It comes with an easy-to-use IDE that can be downloaded here.

Untitled

The complete program of the dice is here. Just connect up the Arduino board to the computer using the USB cable and launch the IDE to upload the program. Would be fun to see some tinkering with the program to provide different behavior of the dice.


#define RANDOM 1
#define PICKED 2
#define BOUNCEDELAY 50
int state;
void setup()
{
  pinMode(7, INPUT);
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  state = 1;
  Serial.begin(9600);
}
int reading = 0;
int button = 0;
int last_button = 0;
int picked = 0;
void loop()
{
  if (state == RANDOM) {
    digitalWrite(2, HIGH);
    digitalWrite(3, LOW);
    digitalWrite(4, LOW);
    delay(50);
    digitalWrite(2, LOW);
    digitalWrite(3, HIGH);
    digitalWrite(4, LOW);
    delay(50);
    digitalWrite(2, LOW);
    digitalWrite(3, LOW);
    digitalWrite(4, HIGH);
    delay(50);
  } else if (state == PICKED) {
    digitalWrite(2, LOW);
    digitalWrite(3, LOW);
    digitalWrite(4, LOW);
    digitalWrite(picked, HIGH);
  }
  reading = digitalRead(7);
  if (reading == last_button) {
    button = reading;
  } else {
   last_button = reading;
  }
  if (button == 1) {
    state = RANDOM;
  } else {
    state = PICKED;
    if (button != last_button) {
      picked = random(3) + 2;
    }
  }
}
]]>

Tagged , ,

Leave a Reply

Your email address will not be published. Required fields are marked *

What's this?

You are currently reading Electronic Dice at 新车间 [XinCheJian].

meta