Saturday, November 14, 2020

RGB and Multiple LEDs along with a Challenge Build - Week 3 - Adventures of Making

 

This week we had two builds to do and then a challenge of combining two or more builds and making the code work.  The first build was the Driving an RGB LED and the second build was Driving Multiple LEDs. Then for the challenge, I decided I wanted to combine these two challenges and see if I could get them both to work.

         First, Driving an RGB LED was pretty easy to set up and the code made sense for the most part.  The first part of the code has the RGB go through the 8 colors that can be created with it and a delay(1000) which is 1000 milliseconds.  Then the code has the RGB step through the colors the RGB can make by using the variable “x” and having “x” count from 0 to 767.  It uses if/else statements to figure out what color is to be being displayed at that time.  Below is the code I used, a picture of the circuit, and diagrams of the circuit (one I drew and one a fritz).

Picture of my set up.


                                                      Picture of what my board looks like.


Diagrams of the circuit.

Here are pictures of the code I used.  I had to use multiple and get
creative to get it all together.

         Once I got everything set up and the code all ready, I hit upload and the RGB started going through the eight colors, except green was missing.  I didn’t realize green wasn’t showing up until the second loop through when it just went off for a time and then continued.  I looked at the board to realize that the resistor that was supposed to be from d5 to f5 was actually in d5 to f6, so I fixed it and the next cycle I got green.  Now that everything was working, I went to clean up the code and after I got it all cleaned up, I hit verify and got an error message saying that showRGB wasn’t defined.  I looked at it and realized I took the curly bracket out on accident.  I put it back in and it verified again and didn’t get an error.  Wahoo.


RGB working video.

RGB explanation video. 

         Second, Driving Multiple LEDs again was easy to set up the code made sense, though I am not sure I could have figured out how to write the code to make it do all the different things it could.  This program had the circuit turning on LEDs oneAfterAnother, oneOnATATime, pingPong, marquee, and randomLED.  I learned that you can put // in front parts of the functions that are in the void setup() and that makes it become like a comment that the Arduino doesn’t recognize so it doesn’t do anything for it.  This allows you to have different functions that you can run one at a time using the same circuit setup and not have to have a different set of code for each one.  Below is the code I used, a picture of the circuit, and the diagrams of the circuit (one I drew and one a fritz).

Code pictures

Picture of the set up for 
the Multiple LEDs.
Picture of the circuit.

Diagrams of the circuit.

         The code above is the cleaned-up code.  I started with the messy and cleaned it up. I verified the cleaned-up code and got no errors.  I then went through and checked to make sure each loop worked.  They all still worked.  Below is a video with all the different loops working.

 

Video of all the different loops together.

         Last, I moved on to the challenge for the week where I was to put 2 or 3 circuit codes into one program and make the circuit work. I was able to do this by using the two codes and circuits from this week.  I set up by board with the multiple LEDs and then added the RGB, this was the easy part.  Now I needed to combine the two codes to make both work together.  The first time I tried to combine the two codes I started with the Multiple LEDs code and then went in and added the RGB code.  When I hit verify, I got an error saying missing terminating apostrophe instead of a semicolon, so I added the semicolon instead of the apostrophe (typing too fast error) and verified again.  I still got an error saying expected ‘or’, “before ‘void’” this took me a minute to figure out because it wasn’t as clear as the other code.  So, I went back to the printed code I had and realized that I forgot a semicolon after 11 above the line, so I fixed that and tried again.  Third time trying and it works, I got no errors, thank goodness.  I do like that it highlights the area where the error is even if I don’t understand what the error is telling me, it helped me figure it out even if it took a minute.  I now uploaded it to the board and only the multiple LEDs light up and nothing happened to the RGB.  I watched some videos about combining codes to see if I could figure it out.  After about three hours I decided it was time to quit for the night and try again tomorrow afternoon.  So, I started again the next day by making sure each code still worked individually and they both did.  This helped me know that they are correct and that it was the way I was combining them that was creating the problems.  This time I started with the RGB code and added the multiple LED code to it. I verified it and got a couple of error codes about ‘{‘ not being a token.  So, I removed them and verified again and it came back all good (no errors). I then uploaded it to the board and the RGB went through its loop and then the multiple LEDs went through its oneAfterAnotherLoop.  I first thought the RGB wasn’t doing anything but after waiting longer I realized it was still going through the colors just slowly and when it got back to red, it turned off as did the multiple LEDs and the whole thing started over again.  Below is a picture of my setup, the diagram of my circuit for the challenge, the code used, and a video of all it working.

 

Challenge setup.

Challenge diagram.


Pictures of the code used for challenge.


Here is a video of the challenge build.

Challenge Video

         Overall, this week the two builds we were given to do were easy to setup up the circuits and the codes seemed to make sense but again, I am not sure I would have been able to come up with them.  The challenge part of this week also was easy for the circuit setup but the coding part was frustrating and I am still not sure why I worked the way I did it the second time but not the way I did it the first time.  The RGB can be seen in video game consoles because they need to show different colors all in the same area at once.  I also think that it is used in controllers for video games that light up different colors in one spot as the player uses it.  The Multiple LEDs circuit can be seen on a flashing marquee sign that is trying to get peoples attention but it is also used in my husbands’ keyboard for his computer as it is backlit and changes colors slowly or fast depending on what he wants it to do (normally on slow because fast gives him a headache).  He can also make it light in different patterns and ways just like I was able to get the multiple LED circuit to do.  I am hoping that I have learned enough that I will be able to complete my own build setup and code to make that build work that we supposedly have coming up next week.  Now to take a day brain break before next week's Adventures in Making and class work.

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...