ELECTRONIC DICE USING CLOUDX M633 CloudX

  • img
Project Details

We must all have played the game of chance in one way or the other using the dice. Knowing the very unpredictable nature of what the rolling of the dice would turn out to display further adds much fun game.

i hereby, present an electronic digital dice using simple LEDs, a push button and the CloudX M633 module to implement it.

 

Components

 

 

 

CODE:

#include <CloudX\RandomNumberGenerator.h>

#define switch1 pin16  
#define pressed LOW 

/*holds dice patterns to be outputed on the LEDs */ 
unsigned char die[] = {0, 0x08, 0x14, 0x1C, 0x55, 0x5D,0x77}; 
unsigned char i, dice1, dice2;    

setup(){           
    //setup here                      
    /*configures port pins as output */           
     portMode(1, OUTPUT);             
     portMode(2, 0b10000000);                      
    /*switches all the LEDs off at the start */           
    portWrite(1, LOW);           
    portWrite(2, LOW);                      
    RandNumber_limit(1, 6); //takes care of randomNumber generation range (ie. min, max)   

loop(){           
        //Program here                  
        if(switch1 is pressed) {          
            while(switch1 is LOW);  //waits here until switch is released              
            dice1 = RandNumber_gen();   //generates a random number for dice1              
            dice2 = RandNumber_gen();              
            portWrite(1, die[dice1]);  //fetches the correct dice pattern and displays it               
            portWrite(2, die[dice2]);   
            }          
        else         
           {             
           portWrite(1, die[dice1]);              
           portWrite(2, die[dice2]);  
       }     
   }
}   //End of Program

Share this with friends