WayneSan
Published

Project Example 1: Control a Single LED

Controlling a single LED is easy and useful for observing any programming mistakes - our first Webduino tutorial.

BeginnerProtip1 hour1,360
Project Example 1: Control a Single LED

Things used in this project

Hardware components

Webduino Mark 1
×1
Webduino Fly
×1
Arduino UNO
Arduino UNO
×1
LED (generic)
LED (generic)
×1

Software apps and online services

Webduino Blockly

Story

Read more

Schematics

Webduino Mark 1 Circuit diagram

Webduino Fly Circuit diagram

Code

Code snippet #5

CSS
#demo-area-02-light img{
  height:200px;
  display:none;
}
#demo-area-02-light.on #demo-area-02-on{
  display:inline-block;
}
#demo-area-02-light.off #demo-area-02-off{
  display:inline-block;
}

Code snippet #6

CSS
#demo-area-02-light img{
  height:200px;
  display:none;
}
#demo-area-02-light.on #demo-area-02-on{
  display:inline-block;
}
#demo-area-02-light.off #demo-area-02-off{
  display:inline-block;
}

Code snippet #7

JavaScript
var led;

boardReady('', function (board) {
  board.samplingInterval = 20;
  led = getLed(board, 10);
  document.getElementById("demo-area-02-light").addEventListener("click",function(){
    if (document.getElementById("demo-area-02-light").className == "on") {
      document.getElementById("demo-area-02-light").className = "off";
      led.off();
    } else {
      document.getElementById("demo-area-02-light").className = "on";
      led.on();
    }
  });
});

Code snippet #8

JavaScript
var led;

boardReady('', function (board) {
  board.samplingInterval = 20;
  led = getLed(board, 10);
  document.getElementById("demo-area-02-light").addEventListener("click",function(){
    if (document.getElementById("demo-area-02-light").className == "on") {
      document.getElementById("demo-area-02-light").className = "off";
      led.off();
    } else {
      document.getElementById("demo-area-02-light").className = "on";
      led.on();
    }
  });
});

Code snippet #9

JavaScript
var led;
var light;

boardReady('', function (board) {
  board.samplingInterval = 20;
  led = getLed(board, 10);
    light = document.getElementById("demo-area-02-light");
  light.addEventListener("click",function(){
    if (light.className == "on") {
      light.className = "off";
      led.off();
    } else {
      light.className = "on";
      led.on();
    }
  });
});

Code snippet #10

JavaScript
var led;
var light;

boardReady('', function (board) {
  board.samplingInterval = 20;
  led = getLed(board, 10);
    light = document.getElementById("demo-area-02-light");
  light.addEventListener("click",function(){
    if (light.className == "on") {
      light.className = "off";
      led.off();
    } else {
      light.className = "on";
      led.on();
    }
  });
});

Credits

Webduino

Posted by WayneSan
Thanks to Webduino.

Comments