In this lab, you’ll dive further into LEDs. You’ll use an RGB LED and multiple LEDs.
1. Open up the tutorial booklet that you downloaded last week. Go through the packing list. Do you have everything?
2. You already started to get to know your Arduino better, but you may want to keep getting acquainted by re-reading Chapter 2 of Arduino for Dummies (posted on Canvas).
3. In class you ran the Blink sketch, which is Lesson 2 in your your book. If you’re still having questions about how it works, review Lesson 2. Carefully read the code and the explanation of the code provided in the lesson. With your finger, trace the path of the current from the positive terminal to the ground. Trace it through the LED and the resistor. Where is the current flowing?
4. Do Lesson 4. Read through the exercise closely. What is Pulse Width Modulation? Read through the code closely. Go through it line by line. What is happening in the loops? Why are the numbers incrementing as they are? What does +=
and -=
do? If you don’t understand why the code uses analogWrite(), read about it here.
5. Let’s play with the code. Comment out (i.e., insert two forward slashes, //) before the first for loop. Upload the code again. How does the light change? Why does it change?
6. Now adjust the delay times in the loops. Make them big. Make them small. What happens?
7. Wire the board so there is now the RGB LED and two additional regular LEDs that are all being powered by separate pins. Write a new sketch that makes the lights visibly blink sequentially. Make the RGB LED blink the color purple (on and off), and THEN then blink one regular LED, and THEN blink the next regular LED. You may re-use (i.e., copy/paste and combine) code from Lesson 2 and Lesson 4.
8. Save your Arduino sketch. In comments the top of your code include your name, the date, and a short paragraph stating what your project does (you must always write this kind of description at the top of your code this semester). Cite all the code you’re building from within the header (e.g., “This project extends ELEGOO Lessons 2 and 4” — usually it’s appropriate to provide a link, but we don’t have one in this case). (1 point)
9. Clean up your code so that it is well organized and easy for someone else to read. For example, group related lines of code in a block and add empty lines between blocks. (2 points)
10. Make sure your variable naming makes sense. Good naming practices can eliminate the need of annotation in some instances, creating concise yet understandable scripts. (1 point)
- Each variable name should be self-explanatory; e.g.,
BLUE_LED
instead of justblue
. - Avoid abbreviations, except when the abbreviation is widely accepted and recognized.
- Avoid simply concatenating words; use
snakeCase
orsnake_case
for variables, or SNAKE_CASE for constants. - At times, it may be helpful to add units. E.g., use
delayMilliseconds
instead of justdelay
.
10. Annotate your code with comments, like you saw in both the Blink and RGB sketches. Describe what the different blocks of code do. As needed, describe what a particular line of code does. Writing well-commented code is so important! (2 points)
11. Submit a photo of your board so all the wiring is visible. (1 point)
12. Create a short (< 30 sec) video of your project so that we can see it works. (2 points)
13. Make your own wiring diagram with circuito.io or another similar app of your choosing.
- Add an Arduino UNO R3 and a RGB LED to the diagram.
- Your final wiring diagram should look similar to the diagram on page 52 of the ELEGOO instruction book.
- Compare your wiring diagram to the schematic on page 51. A schematic will feel less familiar to most of you, but it is the most common way to draw circuit diagrams. Can you see how the wiring diagram and schematic relate to each other? Schematics may initially seem more complicated looking, but they can also be more helpful than wiring diagrams.
14. Submit a copy of your wiring diagram. (1 point)
15. Please submit your work on Canvas under Assignments, Lab 1. You will turn in your code, photo and your video, as described in steps 8-12 and 14.