Dicey
Easy Arduino dice project, great for beginners learning how to create homemade functions.
Components and supplies
Breadboard (generic)
Arduino UNO
LED (generic)
Resistor 221 ohm
Jumper wires (generic)
Apps and platforms
Arduino IDE
Project description
Code
dicey.ino
c_cpp
1int onePin = 1; 2int twoPin = 2; 3int threePin = 3; 4int fourPin = 4; 5int fivePin = 5; 6int sixPin = 6; //six leds connected with 220 ohm resistors 7void setup() { 8 // put your setup code here, to run once: 9Serial.begin(9600); 10randomSeed(analogRead(0)); 11pinMode(onePin,OUTPUT); 12pinMode(twoPin,OUTPUT); 13pinMode(threePin,OUTPUT); 14pinMode(fourPin,OUTPUT); 15pinMode(fivePin,OUTPUT); 16pinMode(sixPin,OUTPUT); 17} 18 19void loop() { 20int number = random(1,7); //find random number and do void 1,6 accordingly 21if (number==1) 22 one(); 23else if(number==2) 24 two(); 25else if (number==3) 26 three(); 27else if (number==4) 28 four(); 29else if (number==5) 30 five(); 31else if (number==6) 32 six(); 33} 34void one() 35 { 36 Serial.println("one"); //Serial monitor also runs for viewing 37 digitalWrite(onePin,HIGH); 38 delay(50000); 39 digitalWrite(onePin,LOW); 40 delay(1000); 41 } 42void two() 43 { 44 Serial.println("two"); 45 digitalWrite(onePin,HIGH); 46 digitalWrite(twoPin,HIGH); 47 delay(50000); 48 digitalWrite(onePin,LOW); 49 digitalWrite(twoPin,LOW); 50 delay(1000); 51 } 52void three() 53 { 54 Serial.println("three"); 55 digitalWrite(onePin,HIGH); 56 digitalWrite(twoPin,HIGH); 57 digitalWrite(threePin,HIGH); 58 delay(50000); 59 digitalWrite(onePin,LOW); 60 digitalWrite(twoPin,LOW); 61 digitalWrite(threePin,LOW); 62 delay(1000); 63 } 64void four() 65 { 66 Serial.println("four"); 67 digitalWrite(onePin,HIGH); 68 digitalWrite(twoPin,HIGH); 69 digitalWrite(threePin,HIGH); 70 digitalWrite(fourPin,HIGH); 71 delay(50000); 72 digitalWrite(onePin,LOW); 73 digitalWrite(twoPin,LOW); 74 digitalWrite(threePin,LOW); 75 digitalWrite(fourPin,LOW); 76 delay(1000); 77 } 78void five() 79 { 80 Serial.println("five"); 81 digitalWrite(onePin,HIGH); 82 digitalWrite(twoPin,HIGH); 83 digitalWrite(threePin,HIGH); 84 digitalWrite(fourPin,HIGH); 85 digitalWrite(fivePin,HIGH); 86 delay(50000); 87 digitalWrite(onePin,LOW); 88 digitalWrite(twoPin,LOW); 89 digitalWrite(threePin,LOW); 90 digitalWrite(fourPin,LOW); 91 digitalWrite(fivePin,LOW); 92 delay(1000); 93 } 94void six() 95 { 96 Serial.println("six"); 97 digitalWrite(onePin,HIGH); 98 digitalWrite(twoPin,HIGH); 99 digitalWrite(threePin,HIGH); 100 digitalWrite(fourPin,HIGH); 101 digitalWrite(fivePin,HIGH); 102 digitalWrite(sixPin,HIGH); 103 delay(50000); 104 digitalWrite(onePin,LOW); 105 digitalWrite(twoPin,LOW); 106 digitalWrite(threePin,LOW); 107 digitalWrite(fourPin,LOW); 108 digitalWrite(fivePin,LOW); 109 digitalWrite(sixPin,LOW); 110 delay(1000); 111 } 112 113 114
dicey.ino
c_cpp
1int onePin = 1; 2int twoPin = 2; 3int threePin = 3; 4int fourPin 5 = 4; 6int fivePin = 5; 7int sixPin = 6; //six leds connected with 8 220 ohm resistors 9void setup() { 10 // put your setup code here, to run once: 11Serial.begin(9600); 12randomSeed(analogRead(0)); 13pinMode(onePin,OUTPUT); 14pinMode(twoPin,OUTPUT); 15pinMode(threePin,OUTPUT); 16pinMode(fourPin,OUTPUT); 17pinMode(fivePin,OUTPUT); 18pinMode(sixPin,OUTPUT); 19} 20 21void 22 loop() { 23int number = random(1,7); //find random number and do void 1,6 accordingly 24if 25 (number==1) 26 one(); 27else if(number==2) 28 two(); 29else if (number==3) 30 31 three(); 32else if (number==4) 33 four(); 34else if (number==5) 35 five(); 36else 37 if (number==6) 38 six(); 39} 40void one() 41 { 42 Serial.println("one"); 43 //Serial monitor also runs for viewing 44 digitalWrite(onePin,HIGH); 45 46 delay(50000); 47 digitalWrite(onePin,LOW); 48 delay(1000); 49 } 50void 51 two() 52 { 53 Serial.println("two"); 54 digitalWrite(onePin,HIGH); 55 digitalWrite(twoPin,HIGH); 56 57 delay(50000); 58 digitalWrite(onePin,LOW); 59 digitalWrite(twoPin,LOW); 60 61 delay(1000); 62 } 63void three() 64 { 65 Serial.println("three"); 66 67 digitalWrite(onePin,HIGH); 68 digitalWrite(twoPin,HIGH); 69 digitalWrite(threePin,HIGH); 70 71 delay(50000); 72 digitalWrite(onePin,LOW); 73 digitalWrite(twoPin,LOW); 74 75 digitalWrite(threePin,LOW); 76 delay(1000); 77 } 78void four() 79 { 80 81 Serial.println("four"); 82 digitalWrite(onePin,HIGH); 83 digitalWrite(twoPin,HIGH); 84 85 digitalWrite(threePin,HIGH); 86 digitalWrite(fourPin,HIGH); 87 delay(50000); 88 89 digitalWrite(onePin,LOW); 90 digitalWrite(twoPin,LOW); 91 digitalWrite(threePin,LOW); 92 93 digitalWrite(fourPin,LOW); 94 delay(1000); 95 } 96void five() 97 { 98 99 Serial.println("five"); 100 digitalWrite(onePin,HIGH); 101 digitalWrite(twoPin,HIGH); 102 103 digitalWrite(threePin,HIGH); 104 digitalWrite(fourPin,HIGH); 105 digitalWrite(fivePin,HIGH); 106 107 delay(50000); 108 digitalWrite(onePin,LOW); 109 digitalWrite(twoPin,LOW); 110 111 digitalWrite(threePin,LOW); 112 digitalWrite(fourPin,LOW); 113 digitalWrite(fivePin,LOW); 114 115 delay(1000); 116 } 117void six() 118 { 119 Serial.println("six"); 120 digitalWrite(onePin,HIGH); 121 122 digitalWrite(twoPin,HIGH); 123 digitalWrite(threePin,HIGH); 124 digitalWrite(fourPin,HIGH); 125 126 digitalWrite(fivePin,HIGH); 127 digitalWrite(sixPin,HIGH); 128 delay(50000); 129 130 digitalWrite(onePin,LOW); 131 digitalWrite(twoPin,LOW); 132 digitalWrite(threePin,LOW); 133 134 digitalWrite(fourPin,LOW); 135 digitalWrite(fivePin,LOW); 136 digitalWrite(sixPin,LOW); 137 138 delay(1000); 139 } 140 141 142
Downloadable files
Diagram
Diagram
Diagram
Diagram
Comments