Get the LEDs working

Let's brainstorm, what do we know about LEDs? We know how they work, we know there is an example on making LEDs blink, we know how we can use the LED on pin 13 to do quick checks if the board is working fine.

As a first step, let's get the LEDs working through the pin 13 using the LED blink example. You already know how to navigate to the example don't you my friend?

Here is how the code looks like right now:

Get the LEDs working

Code:

// the setup function runs once when you press reset or power the board
void setup(){
  // initialize digital pin 13 as an output.
  pinMode(13, OUTPUT); 
} 
// the loop function runs over and over again forever
void loop() {
  digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
  delay(1000); // wait for a second
  digitalWrite(13, LOW); // turn the LED off by making the voltage LOW
  delay(1000); // wait for a second
} 

Let's go ahead and upload this code on our board. I am using an Arduino Uno for this one. You know how to upload the program right? Refer back to Chapter 1, The World around Us if it slipped out of my mind. Come back here once you upload is done.

Keep checking out the console window (green/black window at the bottom of the IDE). If you see any form of errors, remember, we have learnt how to navigate ourselves in these situations. What do we do? Google it and figure out where the problem could have been.

Ok, we should have our LED on pin 13 blinking now. We will move on to the next step and test how would it look if we could control the blinking of the LEDs through an external influence. Let's use a switch to test this. We will press the switch and switch the LED on and off on the basis of the switch press.

Note

Curious about why we are doing this? Why a switch? Think about it and write it down in your notebook.

..................Content has been hidden....................

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