Tuesday, November 25, 2014

ETEC 597: Maker Movement - Week 4

The project this time around was especially challenging since it did not directly add on to previous builds.  Google was especially helpful; I found a great resource for building the dice simulator on the Instructables website.  After carefully assembling the circuit (with tweezers because of the small connectors on the resistors), I carefully re-typed the code to load to the Arduino board.  I definitely have more appreciation for the coders that came up with this program after typing it line by line; especially with my affinity for transposing numbers.

Picture of the Arduino Circuit



Arduino Schematics
Circuit with the Switch
Circuit without the Switch

Dice Code
int pinLeds1 = 10;
int pinLeds2 = 9;
int pinLeds3 = 7;
int pinLed4 = 8;
int buttonPin = 6;
int buttonState;
long ran;
int time = 2000;

void setup ()
{
  pinMode (pinLeds1, OUTPUT);
  pinMode (pinLeds2, OUTPUT);
  pinMode (pinLeds3, OUTPUT);
  pinMode (pinLed4, OUTPUT);
  pinMode (buttonPin, INPUT);
  randomSeed(analogRead(0));
}

void loop()
{
  buttonState = digitalRead(buttonPin);
  if (buttonState == HIGH){
    ran = random(1, 7);
    if (ran == 1){
      digitalWrite (pinLed4, HIGH);
      delay (time);
    }
    if (ran == 2){
      digitalWrite (pinLeds1, HIGH);
      delay (time);
    }
    if (ran == 3){
      digitalWrite (pinLeds3, HIGH);
      digitalWrite (pinLed4, HIGH);
      delay (time);
    }
    if (ran == 4){
      digitalWrite (pinLeds1, HIGH);
      digitalWrite (pinLeds3, HIGH);
      delay (time);
    }
    if (ran == 5){
      digitalWrite (pinLeds1, HIGH);
      digitalWrite (pinLeds3, HIGH);
      digitalWrite (pinLed4, HIGH);
      delay (time);
   }
   if (ran == 6){
      digitalWrite (pinLeds1, HIGH);
      digitalWrite (pinLeds2, HIGH);
      digitalWrite (pinLeds3, HIGH);
      delay (time);
   }
  }
  digitalWrite (pinLeds1, LOW);
  digitalWrite (pinLeds2, LOW);
  digitalWrite (pinLeds3, LOW);
  digitalWrite (pinLed4, LOW);

}

Videos
Circuit with the Switch
Circuit without the Switch

Roll Distributions
You can see that the distribution is nearly normal; my guess is that the outcome of 4 would be on par with the 3 and the 5 if we were to do several more rolls.

Commentary
The complexities of each circuit have definitely increased from week to week.  I have even more appreciation for those EE's that have impacted our life with the electronic tools that we use and love.  Even something as simple as a Dice simulator took some considerable effort; I can only imagine the time and the manpower required to produce a smartphone!  

A good extension to this project would be to envision the programming and circuitry involved in a gaming machine (such as a slot machine) at a casino.  Electronic slot machines or other gaming machines have more circuits than I can imagine with thousands upon thousands of lines of code.  I would like to be able to peer inside of something a little more complex than our Dice simulator one day; perhaps a combination of multiple "Dice" banks would be a better simulation of these games of chance.

No comments:

Post a Comment