Project Name : Elaectronic playing Cube ( The Qube).
Project description:
This gadget will roll randomly a playing cube (the Qube) and will display the result in leds arrangement.
The random number are seeded from a "electronic noise" from analog pin of the Arduino. This to ensure real random number all the time. (Avoiding repeating sequence).
Components :
Seven (7) leds to represent the rolled number.
Push Button - to start the roll.
A small red led at the lower left lit while the cube is rolling.
contact to yohizu@gmail.com
The code
======
/*
Game Cube(1 to 6)
This example code is in the public domain.
Create 13 January 2014
by Yohi Zucker
*/
int i;//counter
int r;//hold the random nomber 1 to 6
//int ledPins[]={5,6,7,8,9,10,11};
const int button1Pin=2; // pushbutton1 pin
const int ledPin= 13; // LED pin
void setup() {
// initialize digital pins as an output.
for(i=5;i<13;i++){
pinMode(i, OUTPUT);}
pinMode(ledPin,OUTPUT);
randomSeed(analogRead(0));;
Serial.begin(9600);
}
void loop() {//Main LOOP
int button1State; // variable to hold the pushbutton state
button1State=digitalRead(button1Pin);
digitalWrite(ledPin,LOW);
if (button1State==LOW) //we push the button
{
digitalWrite(ledPin,HIGH);
for (int j=0;j,j<25 ;j++)
{
int rr=random(5,12);//random leds lite for new scrolling.
digitalWrite( rr,HIGH);
delay(\(\(\(50);
digitalWrite (rr,LOW);
}
digitalWrite(5,LOW);//clearing all leds before showing the scroll
digitalWrite(6,LOW);
digitalWrite(7,LOW);
digitalWrite(9,LOW);
digitalWrite(10,LOW);
digitalWrite(11,LOW);
// Main Scrolling loop start here
r=random(1,7);//randimly a number between 1 to 6
switch (r) {
case 1://lite muddke led for 1
digitalWrite(8,HIGH);
delay(\(\(\(100);
// digitalWrite(8,LOW);
break;
case 2://lite 2 corners leds for 2
digitalWrite(7,HIGH);
digitalWrite(9,HIGH);
digitalWrite(8,LOW);//clearing middle led
delay(\(\(\(100);
//digitalWrite(7,LOW);
//digitalWrite(8,LOW);
//digitalWrite(9,LOW);
break;
case 3://lite 3 leds in karnezol
digitalWrite(7,HIGH);
digitalWrite(8,HIGH);
digitalWrite(9,HIGH);
delay(\(\(\(100);
// digitalWrite(7,LOW);
//digitalWrite(8,LOW);
//digitalWrite(9,LOW);
break;
case 4://lite 4 corners leds
digitalWrite(5,HIGH);
digitalWrite(7,HIGH);
digitalWrite(9,HIGH);
digitalWrite(11,HIGH);
digitalWrite(8,LOW);//clearing middle led
delay(\(\(\(100);
// digitalWrite(5,LOW);
// digitalWrite(7,LOW);
// digitalWrite(9,LOW);
//digitalWrite(11,LOW);
break;
case 5://lite corners leds and middlr led
digitalWrite(5,HIGH);
digitalWrite(7,HIGH);
digitalWrite(8,HIGH);
digitalWrite(9,HIGH);
digitalWrite(11,HIGH);
delay(\(\(\(100);
// digitalWrite(5,LOW);
//digitalWrite(7,LOW);
//digitalWrite(8,LOW);
//digitalWrite(9,LOW);
//digitalWrite(11,LOW);
break;
case 6://lite all 6 keds and clear the middle one
digitalWrite(5,HIGH);
digitalWrite(6,HIGH);
digitalWrite(7,HIGH);
digitalWrite(9,HIGH);
digitalWrite(10,HIGH);
digitalWrite(11,HIGH);
digitalWrite(8,LOW);
delay(\(\(\(100);
// digitalWrite(5,LOW);
//digitalWrite(6,LOW);
//digitalWrite(7,LOW);
//digitalWrite(9,LOW);
//digitalWrite(10,LOW);
//digitalWrite(11,LOW);
break;
}
}
Serial.println(r);
delay(\(\(\(10);
}