Hey everyone. Are you tired of playing a snake and ladder or ludo with old dice? So hence I bought you the digital version of dice.
Connections:
1) One pin of push button to 2 of arduino and resistor
2) Another pin of push button to 5V of arduino
3) Take 7 leds
4) Positive of them to 3, 4, 5, 6, 7, 8, 9
5) negative of leds to gnd of arduino
CODE:
int x, y, z;
void setup() {
// put your setup code here, to run once:
pinMode(2, INPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
x=0;
y=x++;
delay(1);
x=y++;
delay(1);
if (x==6){
delay(1);
int x=1;}+
if(digitalRead(2)==HIGH&&x==1)
{digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(7, LOW);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
}
if(digitalRead(2)==HIGH&&x==2)
{digitalWrite(3, LOW);
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
digitalWrite(6, LOW);
digitalWrite(7, HIGH);
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
}
if(digitalRead(2)==HIGH&&x==3)
{digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
digitalWrite(7, HIGH);
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
}
if(digitalRead(2)==HIGH&&x==4)
{digitalWrite(3, HIGH);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
digitalWrite(6, HIGH);
digitalWrite(7, LOW);
digitalWrite(8, LOW);
digitalWrite(9, HIGH);
}
if(digitalRead(2)==HIGH&&x==4)
{digitalWrite(3, HIGH);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
digitalWrite(6, HIGH);
digitalWrite(7, LOW);
digitalWrite(8, LOW);
digitalWrite(9, HIGH);
}
if(digitalRead(2)==HIGH&&x==5)
{digitalWrite(3, HIGH);
digitalWrite(4, LOW);
digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
digitalWrite(7, LOW);
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
}
if(digitalRead(2)==HIGH&&x==6)
{digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
digitalWrite(7, LOW);
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
}
}
ADVERTIZEMENT:
**********************Don’t skip**************************
Are you interested in making your own arduino project and rely on mysources.
If you rely on my sources then you might have your own ideas thatneither I have not uploaded or nor others. So you might leave the hopes oncompleting that project. But there is no need for youas I will helpyou out personally. Yes you heard it right. I will complete your project. Allyou need is just to press this link.
https://www.freelancer.in/hireme/pranavmadhavaram
*****************advertisementcompleted******************
Precaution: arrange leds in the same way I arranged in schematic diagram
How it works: when you read the project you might be thinking it is impossible and I was one of them as arduino can’t take random options. So one of the options is to make it in a loop where if number 1 is first choice then number 2 is second outcome then it repeats. But it would be easy to predict it. So I made it in a way where after each millisecond the value of the outcome increases and after it reaches 6 in a millisecond it again starts from it look
s like it is random but deep it is not.
Comments