I am brand new (two days in) to Arduino, and have gone from excited to feeling like there is so much to learn, to inspired, to down right frustrated (though its been immensely exciting for the most part!). I am currently trying to build a Craps game, and am stuck... I have gotten to the point where at the press of the button the 2 seven segment displays randomize a number, though I can not for the life of me figure out how to then store that value (as to compare, and add together to store a point, or determine a frontline winner / craps number). Here is the code as it stands right now:
// Craps game
// Uses two seperate pseudo-random number generators to simulate rolling dice
// then observes simplified rules of game "Craps", and lights Green LED for frontline wins.
// Red led for Craps.
// Dice value arrays, as cooresponding to digital output pins used
byte seven_seg_digitsLeft[7][7] = { { 0,0,0,0,0,0,1 }, // = 0
{ 1,0,0,1,1,1,1 }, // = 1
{ 0,0,1,0,0,1,0 }, // = 2
{ 0,0,0,0,1,1,0 }, // = 3
{ 1,0,0,1,1,0,0 }, // = 4
{ 0,1,0,0,1,0,0 }, // = 5
{ 0,1,0,0,0,0,0 }
};
byte seven_seg_digitsRight[7][7] = { { 0,0,0,0,0,0,1 }, // = 0
{ 1,0,0,1,1,1,1 }, // = 1
{ 0,0,1,0,0,1,0 }, // = 2
{ 0,0,0,0,1,1,0 }, // = 3
{ 1,0,0,1,1,0,0 }, // = 4
{ 0,1,0,0,1,0,0 }, // = 5
{ 0,1,0,0,0,0,0 }
};
void setup() {
// Pin assignments for individual segments in 7 - segment displays (2-8 & 40-46)
// Pin assignments for Win/Lose LED's (30,32)
// PIn assignments for Roll Switch (36,38)
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(40, OUTPUT);
pinMode(41, OUTPUT);
pinMode(42, OUTPUT);
pinMode(43, OUTPUT);
pinMode(44, OUTPUT);
pinMode(45, OUTPUT);
pinMode(46, OUTPUT);
pinMode(22, INPUT);
pinMode(36, OUTPUT);
pinMode(37, OUTPUT);
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
digitalWrite(7, HIGH);
digitalWrite(8, HIGH);
digitalWrite(40, HIGH);
digitalWrite(41, HIGH);
digitalWrite(42, HIGH);
digitalWrite(43, HIGH);
digitalWrite(44, HIGH);
digitalWrite(45, HIGH);
digitalWrite(46, HIGH);
randomSeed(analogRead(0));
}
// setting up value limits to seven segment displays
void sevenSegWriteLeft(byte digit)
{
byte pinLeft = 2;
for (byte segCountLeft = 0; segCountLeft <= 6; ++segCountLeft)
{
digitalWrite(pinLeft, seven_seg_digitsLeft[digit][segCountLeft]);
++pinLeft;
}
}
void sevenSegWriteRight(byte digit)
{
byte pinRight = 40;
for (byte segCountRight = 0; segCountRight <= 6; ++segCountRight)
{
digitalWrite(pinRight, seven_seg_digitsRight[digit][segCountRight]);
++pinRight;
}
}
void loop() {
long int diceLeft, diceRight;
if (digitalRead(22) == LOW) // "ROLL Dice" Switch
{
for (byte countLeft = 6; countLeft > 0; countLeft = random(0,6)) // Randomized output for left dice (left 7-seg display)
{
delay(25);
sevenSegWriteLeft(countLeft);
}
for (byte countRight = 6; countRight > 0; countRight = random(0,6)) // randomized output for right dice
{
delay(25);
sevenSegWriteRight(countRight);
}
}
}
I believe that I would have to convert the byte state at the conclusion of the "if" statements to int to recall later, but as new as I am that is just a guess. Any help would be amazing!!
Thank You!