LinkIt ONE Tutorial - Push Button

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



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

Copyright (c) 2008-2016 Seeed Development Limited (www.seeedstudio.com / www.seeed.cc)
This static html page was created from http://www.seeedstudio.com/wiki