Created
January 9, 2018 12:33
-
-
Save elktros/60a7e72b9f7be36622da06c3508bdfd3 to your computer and use it in GitHub Desktop.
Arduino Code for Rolling Dice function using Arduino and 7 Segment Display.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//e = 2; | |
//d = 3; | |
//c = 4; | |
//g = 5; | |
//f = 6; | |
//a = 7; | |
//b = 8; | |
int num[10][7]={ {0,0,0,1,0,0,0}, | |
{1,1,0,1,1,1,0}, | |
{0,0,1,0,1,0,0}, | |
{1,0,0,0,1,0,0}, | |
{1,1,0,0,0,1,0}, | |
{1,0,0,0,0,0,1}, | |
{0,0,0,0,0,1,1}, | |
{1,1,0,1,1,0,0}, | |
{0,0,0,0,0,0,0}, | |
{1,0,0,0,0,0,0} | |
}; | |
long r_num; | |
int roll = 12; | |
bool state = true; | |
void setup() | |
{ | |
pinMode(2,OUTPUT); | |
pinMode(3,OUTPUT); | |
pinMode(4,OUTPUT); | |
pinMode(5,OUTPUT); | |
pinMode(6,OUTPUT); | |
pinMode(7,OUTPUT); | |
pinMode(8,OUTPUT); | |
pinMode(9,OUTPUT); | |
pinMode(12,INPUT_PULLUP); | |
digitalWrite(2,HIGH); | |
digitalWrite(3,HIGH); | |
digitalWrite(4,HIGH); | |
digitalWrite(5,HIGH); | |
digitalWrite(6,HIGH); | |
digitalWrite(7,HIGH); | |
digitalWrite(8,HIGH); | |
digitalWrite(9,HIGH); | |
randomSeed(analogRead(0)); | |
} | |
void loop() | |
{ | |
if(state) | |
{ | |
r_num=random(1,6); | |
for(int i=0;i<7;i++) | |
{ | |
digitalWrite(i+2,num[r_num][i]); | |
} | |
//delay(1500); | |
state=false; | |
} | |
while(digitalRead(roll)==LOW) | |
{ | |
for(int i=0;i<10;i++) | |
{ | |
for(int j=0;j<7;j++) | |
{ | |
digitalWrite(j+2,num[i][j]); | |
} | |
delay(50); | |
} | |
state=true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment