Devices & Components
Arduino Uno Rev3
Solderless Breadboard Full Size
Jumper wires (generic)
Tilt Switch, SPST
Solderless Breadboard Half Size
LED (generic)
Project description
Code
Code
arduino
Just upload this :)
1 2#define NO_SPECIAL 3 3 4int l1=7; 5int l2=6; 6int l3=5; 7 8int roll[]={NO_SPECIAL,4,1,6,5,2}; 9 10int tiltSwitchpin=2; 11int val; 12int count; 13int num; 14void setup() 15{ 16 pinMode(tiltSwitchpin,INPUT_PULLUP); 17 pinMode(l1,OUTPUT); 18 pinMode(l2,OUTPUT); 19 pinMode(l3,OUTPUT); 20 count=0; 21} 22 23void loop() 24{ 25 val=digitalRead(tiltSwitchpin); 26 if(val==HIGH) { 27 pulseIn(tiltSwitchpin,LOW); 28 dice(); 29 } 30} 31 32void dice(){ 33 if(count>5) 34 count=0; 35 num=roll[count]; 36 37 count++; 38 results(); 39 return; 40} 41 42void results(){ 43 int b1,b2,b3; 44 int temp; 45 temp=num; 46 b3=temp%2; 47 temp/=2; 48 b2=temp%2; 49 temp/=2; 50 b1=temp%2; 51 digitalWrite(l3,b3); 52 digitalWrite(l2,b2); 53 digitalWrite(l1,b1); 54 return; 55}
Downloadable files
Schematic
Schematic

Schematic
Schematic

Comments
Only logged in users can leave comments