debanshudas23
Published © GPL3+

Arduino Physical Dice

The same feel of the traditional dice given a modern makeover using the awesome Arduino

IntermediateFull instructions provided556
Arduino Physical Dice

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Tilt Switch, SPST
Tilt Switch, SPST
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Solderless Breadboard Half Size
Solderless Breadboard Half Size
×1
Solderless Breadboard Full Size
Solderless Breadboard Full Size
×1
LED (generic)
LED (generic)
×1

Story

Read more

Schematics

Schematic

Code

Code

Arduino
Just upload this :)
#define NO_SPECIAL 3

int l1=7;
int l2=6;
int l3=5;

int roll[]={NO_SPECIAL,4,1,6,5,2};
      
int tiltSwitchpin=2; 
int val;            
int count;
int num;
void setup()
{
  pinMode(tiltSwitchpin,INPUT_PULLUP);
  pinMode(l1,OUTPUT);
  pinMode(l2,OUTPUT);
  pinMode(l3,OUTPUT);
  count=0;
}

void loop()
{
  val=digitalRead(tiltSwitchpin);
  if(val==HIGH)   {                                 
    pulseIn(tiltSwitchpin,LOW);
    dice();
  }
}

void dice(){
  if(count>5)
    count=0;
  num=roll[count];

  count++;
  results();
  return;
}

void results(){
  int b1,b2,b3;
  int temp;
  temp=num;
  b3=temp%2;
  temp/=2;
  b2=temp%2;
 temp/=2;
  b1=temp%2;
 digitalWrite(l3,b3);
 digitalWrite(l2,b2);
 digitalWrite(l1,b1);
  return;
}

Credits

debanshudas23

debanshudas23

0 projects • 11 followers

Comments