C H A P T E R  3

Working with Variables

In our last project, there is nothing in the sketch except for our comments that helps us to identify which color LED is connected to which pin on the Arduino board, or, for that matter, what color we are turning on or off at any given time in the code. We would just have to remember that the number 9 in the line digitalWrite(9, HIGH); refers to the Arduino pin 9 that the red LED is connected to. Rather than trying to remember these things, because honestly we will forget or the next person we share our code with will have no clue, there is a better way to write our code using something called variables.

In this chapter, we will revisit the last project, pulling from our magic hat to create seven colors out of our three-color LED as a way to talk about the many uses for variables and how we can put them to work for us. We will also look at a few ways to manipulate variables using several different kinds of operators and how they work. For this new project, we will use the same hardware from the last chapter, but it might be a good idea to briefly mention them here again.

What’s needed for this chapter:

  • Arduino Uno
  • 5mm RGB LED with common cathode
  • 1x 330 ohm and 2x 220 ohm ¼ watt resistors or similar
  • Hookup wires
  • Solderless breadboard
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset