Sunday, November 25, 2018

Success or Failure Sometimes Its Like the Roll of the Dice!!

This week our assignment was to create our own code to make 7 LED simulate the different sides of a dice using a push button to simulate the rolling of the dice.  This just about blew my mind.  I watched Dr. B's video many times and took notes.  I watched the information about the way to use the functions in my code.  I looked through my Guide book for my Arduino.   The same question kept pop up through my brain and panic was setting in. "Where am I going to start".

Well I tried to brake down the assignment but I was still stumped.  Instead panicking I decided to go to the all mighty internet for some help with this as well.  I found a video  (www.pimylifeup.com)  of this challenge with schematics and coding along with the explanation of how to create the boards. I was relieved to have something to use as a tutorial for this project.




On the breadboard I set up the LED's so each LED was located on its own bus.  I placed a resister next to each LED to regulate the current to the LED.  I placed a red jumper wire to the 5v then over to the first positive slot on the breadboard. Then I ran a black jumper wire to the ground under the 5v then over to the first negative  slot on the breadboard. I placed my 7 LED in the same way Dr. B diagrammed in the video onto the breadboard.  Now to place wires from the Arduino to each LED.  I placed a wire to the 12 pin over to the number 7 LED place it next to the LED on the LED's left.  I also placed a resistor by the LED.  I continued to do this with each LED, connecting a wire from pin 11 to LED number 6 pin, wired to the  10 pin   to LED number 5, wired 9 pin to LED number 1, wired the 8 pin to LED number 2, wired to 7 pin to LED number 3 and then  LED number 4 was in the middle is located so it pulls power from the 9 pin as it is positioned so it sets horizontally from the jumper wire.  I placed the push button so it straddles the 2 sections of the breadboard.  I placed a shorter black wire next to the button and ran it to the 1 pin.  I placed a short orange wire above the black wire on the breadboard across to the Arduino pin 1.   I used a 10K resistor next to the button on the positive side.

  At this point I created a diagram of the 7 spots using the correlating number on the Arduino board that the different wires were connect to.
Below is that diagram and also how I have my board wired.



Now it is time to code.  I used the basic code from the example online but soon realized I had to modify it to make this project work.  I spent a total of 8 hours trying to get this to work.  One of the main problems I had was getting the code approved to upload to my computer..  It kept saying the word "all" and the number 6 were not declared in this scope.  I tried to fix this by taking out all of the  "clear all".  It  finally was approved to upload but now I had all of the buttons on.  NOT
WHAT I WANTED.  Back to the drawing board!!!!





When it said the number 6 was not declared in the scope I was differently confused. The number 6 along with the numbers 1-7 were declared at the beginning of the code.  After trying to change the wording, deleting and recopying the original code again I was still out of luck.

Finally I changed Clear all and manually put in All LED to Low delay (4000) so the lights would stay lite for 4 seconds, so random numbers would stay lit for 4 seconds as it randomly rotated on its own.  I was getting closer but when I pushed the button the lights went out instead of changing now I had to figure out how I could revise the action that was happening so the lights changed when I physical pushed the black button.  I was stumped!  Finally, I tried to change the word High to Low on the line of code that said, if (digitalRead (button) == Low && state ==0); and just like that it FINALLY WORKED!!!!! After hours of frustration and feelings of self doubt I was jumping up and down at 1 a.m. with excitement.























                                                        Here is my working project!!!

 The final assignment was to roll the dice 100 times and create a spreadsheet of the results.  Those results are show below.


 Well I hope all of you had a Great Thanksgiving and hopefully next weeks project will go smoother then this week's project.

No comments:

Post a Comment