Thursday, November 19, 2020

Digital Die - Week 4 Adventures in Making Challenge

 

Digital Die, not dice should be the title.  Dice is for more than one die, but if you only have one it is die.  A random piece of information I know, I guess from growing up in a very serious game family.  Anyway, on to this goal of this week, I was supposed to build a circuit and figure out the code that would allow the circuit to light up LEDs to represent numbers like are on a die.  Before I could do this build, I needed to do the basic push button build since I hadn’t done it yet and I wanted to make sure I understood how it worked and could see the code for it.  Here is a couple of pictures of this build.

Left picture: Push Button circuit.

Right picture: Showing the circuit works.


        Now that I understood the push button, I was ready to tackle the build.  I knew that each LED needed a resistor and a jumper wire leading from the positive (anode-long) side of the LED back to a PIN.  The resistors needed to be on the negative (cathode-short) side of the LED and going into a negative slot on the breadboard.  I also know that I need power to the breadboard from the 5V pin and that I need a Ground (negative) from Arduino to both sides of the breadboard since I was using both sides of the breadboard.  I got the Arduino and the breadboard all set up.  I was ready for the code part but I wanted to make sure I understood all the parts that I thought I needed and check to make sure I didn’t see anything else I needed. So, I spent a couple hours looking at the Reference page on the Arduino website.  I ended up calling it a night and would start the code the next day.  The first thing I did in my code was set up all the global codes, this included all the LEDs and telling which pin they were, the push button and its pin, then gave buttonState (so that when it was pushed the Arduino would recognize it, and last a time constraint so that the LEDs would turn off after 2 seconds.  Then, I had to set up the void setup () by making sure I had each LED marked as an OUTPUT and then the push button marked as an INPUT.  I also had to make sure that I had a randomSeed so that I would get a random number each time I pushed the button instead of getting the same number each time.  The last thing I had to do for the code was the void loop ().  I had to make sure the button was recognized as a digitalRead so that if it was high it would run a random search for a number.  I had to then do if statements for each number and use digitalWrite and give the certain pins needed to make each number 1-6 like they are on a die.  Lastly, I had to tell it that once the delay (time) was up that all LEDs needed to turn off or go LOW.   I had it all typed in and I hit verify to make sure there were no errors.  To my surprise, I didn’t get any errors.  I still am in shock that I got no errors.  I then uploaded the code to the Arduino and got nothing.  The circuit didn’t do anything.  I thought that it was probably a push button error because I was still a little confused on exactly the right way for things to go. This is when I noticed that I had the positive jumper wire from 5V (the power to the board) in the + part of the breadboard and realized that the push button needed to have the power since it was the one controlling the LEDs.  I moved the wire to c5 and moved the jumper wire leading from PIN5 to the push button to g5.  This is when I got the lights to work but it appeared that the push button wasn’t doing anything because the LEDs just were lighting up.  So, I decided to pull out the push button to see if it was doing anything, and to my surprise, it was because once I took it out the LEDs went dark.  This is when I put it back so I could keep looking at it and try to figure out what was wrong.  This is when I saw that the positive jumper wire and the jumper wire going from Arduino to the push button were on the same row but on different sides.  I vaguely remembered from my reading and research for this build something about how the legs on the push button run in a row with each other only one way.  I decided to move the push button jumper wire from g5 to g3, so it wasn’t connected to the power through the legs of the push button anymore.  Doing this allowed me to be able to push the button and control the LEDs lighting up.  I might have screamed I was so excited that I got it to work.

        As I was pushing the button and making sure each number showed up so I knew that I had it coded right, I noticed that I coded 3 to be three LEDs in a row instead of a diagonal like on a die.  So, I changed it in the code and checked it and it was right this time. 

Here is the code I used:

int Led1pin = 12;
int Led2pin = 8;
int Led3pin = 7;
int Led4pin = 11;

int Led5pin = 10;

int Led6pin = 9;

int Led7pin = 6;
int buttonpin = 5;
int buttonState;
long ran;
int time = 2000;

void setup ()
{
  pinMode (Led1pin, OUTPUT);
  pinMode (Led2pin, OUTPUT);
  pinMode (Led3pin, OUTPUT);
  pinMode (Led4pin, OUTPUT);

  pinMode (Led5pin, OUTPUT);
  pinMode (Led6pin, OUTPUT);
  pinMode (Led7pin, OUTPUT);
  pinMode (buttonpin, INPUT);
  randomSeed(analogRead(0));
}

void loop()
{
  buttonState = digitalRead(buttonpin);
  if (buttonState == HIGH){
    ran = random(1, 7);
    if (ran == 1){
      digitalWrite (Led7pin, HIGH);
      delay (time);
    }
    if (ran == 2){
      digitalWrite (Led1pin, HIGH);

        digitalWrite (Led6pin, HIGH);
      delay (time);
    }
    if (ran == 3){
      digitalWrite (Led1pin, HIGH);
      digitalWrite (Led2pin, HIGH);

        digitalWrite (Led3pin, HIGH);
      delay (time);
    }
    if (ran == 4){
      digitalWrite (Led1pin, HIGH);
      digitalWrite (Led3pin, HIGH);

        digitalWrite (Led4pin, HIGH);
      digitalWrite (Led6pin, HIGH);
      delay (time);
    }
    if (ran == 5){
      digitalWrite (Led1pin, HIGH);
      digitalWrite (Led3pin, HIGH);

        digitalWrite (Led4pin, HIGH);
      digitalWrite (Led6pin, HIGH);
      digitalWrite (Led7pin, HIGH);
      delay (time);
   }
   if (ran == 6){
      digitalWrite (Led1pin, HIGH);
      digitalWrite (Led2pin, HIGH);

        digitalWrite (Led3pin, HIGH);
      digitalWrite (Led4pin, HIGH);
      digitalWrite (Led5pin, HIGH);
      digitalWrite (Led6pin, HIGH);
      delay (time);
   }
  }
  digitalWrite (Led1pin, LOW);
  digitalWrite (Led2pin, LOW);
  digitalWrite (Led3pin, LOW);
  digitalWrite (Led4pin, LOW);

  digitalWrite (Led5pin, LOW);
  digitalWrite (Led6pin, LOW);
  digitalWrite (Led7pin, LOW);

}

The setup I used for the circuit.

My circuit that I made on Tinkercad.
Trying out something new instead of my
hand-drawn circuits.

Top left picture is the circuit just set up.  Other three are the
showing different numbers through the LEDs that are lit up.

Video of the circuit.

        The next part of the challenge was to “roll” the die 100 times and keep track of the number it showed and make a graph showing the number of times each number randomly came up.

        My final reflection for this build is that the push button was used to create randomization.  I also learned that the push button needs to have power and that the power and wire leading to a PIN on the Arduino that is linked to the push button need to not be on the same row even if they are on opposite sides of the breadboard.  This build really had me nervous and stressed after I first read about it because I wasn’t really sure where to start but thankfully Dr. B had a short video that helped calm me down and made me realize that I can do this and that it is okay to fail and fail again.  For this build, I needed to really pay close attention to details as it had more jumper wires and pieces needed that I needed to make sure everything got in the right place.  This program and circuit could be seen in gaming and is probably used in Vegas.  I think this could be a fun way to use a die or dice (if two or more are needed) to get a number for the children while playing a game or to answer a question.  Overall, I feel that this week went smoother than I thought for the build.

 

        Here is a picture of the layout of my maker space.  Now, this really caused me to spend a lot of time on it because the SketchUp program he suggested was super difficult to use, at least for me. But thanks to some useful YouTube videos I was able to create the space below.

The left wall is green to use as a green screen, the black boxes
 on the tables are 3D printers, and the storage on the bottom 
wall are open space storage that can hold small boxes with supplies.  
There are two windows on the top wall and the door on the bottom wall in the left corner.

Another view of the room.


Final Post: Personal Retrospective

  WOW!!   I am not sure where to begin.   When I saw the assignments and things in week 1, I wasn’t sure what I had really gotten myself i...