LinkIt ONE Tutorial - Push Button

Introduction

What We’re Doing

We now got an insight of how a software and hardware works from the previous chapter. In this chapter we will learn how to integrate both software and hardware for the control of the LED. Make breadboard connections as shown in the Fig 3.2 and upload the code. Now this circuit operates as a two way switch when you press the left side push button switch the LED glows and when the right side push button is pressed the LED is switched OFF.

Things you need

  • LinkIt One x 1

  • Break board x 1

  • Resistors 330Ω,1kΩ x 1

  • Resistor 10kΩ x 2

  • 5mm LED x 1

  • Transistor(2N3904) x 1

  • Push Button switches x 2

Schematic

Connection

Code

Please click on the button below to download the code for the kit:

You can unzip the file to the Examples folder of your Arduino IDE.

To access the demo code open:

File -> Examples -> Starter Kit for LinkIt -> Basic -> L3_Control_LED_Button

const int pinLED = 3;                      // LED connect to D13

const int btnOn  = 5;                       // button on
const int btnOff = 6;                       // button off

void setup()
{
    pinMode(pinLED, OUTPUT);                // set direction of D13-OUTPUT
    pinMode(btnOff, INPUT);                 // set direction of D2-INPUT
    pinMode(btnOn, INPUT);
}

void loop()
{
    if(0 == digitalRead(btnOn))            // button on pressed
    {
        digitalWrite(pinLED, HIGH);
    }

    if(0 == digitalRead(btnOff))
    {
        digitalWrite(pinLED, LOW);
    }
}

Making it better

Keeping the same hardware connection upload the following code. The luminosity brightens when the left push button switch is pressed and fades when the right push button switch is pressed.

To access the demo code open::

File -> Examples -> Starter Kit for LinkIt -> Extend_Lesson –> L3_Brightness

More ideas

How will you modify the code such that the blinking frequency of the LED changes?

Reference

Help us make it better

Welcome to the new documentation system of Seeed Studio. We have made a lot of progress comparing to the old wiki system and will continue to improve it to make it more user friendly and helpful. The improvement can't be done without your kindly feedback. If you have any suggestions or findings, you are most welcome to submit the amended version as our contributor via Github or give us suggestions in the survey below, it would be more appreciated if you could leave your email so that we can reply to you. Happy Hacking!