Gravity: LED Self-lock Switch Button for Arduino/micro:bit WiKi- DFRobot

Introduction

This is a simple LED-illuminated self-lock switch button. It’s just like a basic switch button, but it lights up color(red / yellow / green / blue / white) when pressed down, which gives you visual feedback. These little buttons can be used with micro:bit to realize various fun interactive projects, such as, switch, backlight keyboard, music player panel, recording control panel, etc.

Specification

Note: The module comes with self-lock function. When the button is pressed down, the module outputs High, and the LED lights up. When being pressed again, the module outputs Low and the LED turns off.

Board Overview

Num Silk-screen Description
1 D Control port
2 + VCC
3 - GND

Graphic Programming Tutorial

Connection Diagram

Mind+ Graphic Programming

  1. Download and install the software. Download address: http://mindplus.cc/en.html
  1. Switch to "offline mode". Detailed tutorial: https://mindplus.dfrobot.com/microbit

  2. In "expansion", select "Arduino Uno" in "main controller".

Sample Programm

Function Description: When you first press the button, the LED on it will be lighten up, and the micro:bit dot matrix screen will display "√". When you press the button again, the LED will be off, and the screen will display "×".

Program Effect:

MakeCode Graphic Programming

Click link to Basic operation tutorial for MakeCode.

Sample Program

Function Description: When you first press the button, the LED on it will be lighten up, and the micro:bit dot matrix screen will display "√". When you press the button again, the LED will be off, and the screen will display "×".

Program Effect:

Tutorial for Arduino

Connection Diagram

Requirements

Sample Code


   /*
      Description:
      When you press the button for the first time, its inner LED will be lighten up. At the same time, the LED on pin 13 on the board will be lighten up, too.
      When you press the button again, its inner LED will be off, and the other one on pin 13 will be off as well.

    */


    int ledPin = 13;                // Select the pin of light
    int inputPin = 2;               // Sensor connect pin 2

    void setup() {
      pinMode(ledPin, OUTPUT);      // Define the pin of light as output pin
      pinMode(inputPin, INPUT);     // Define the pin of button as input pin
    }

    void loop(){
      int val = digitalRead(inputPin);  //Read input value
      if (val == HIGH) {            // Check if the input is high, high means the button is pressed down.
         digitalWrite(ledPin, HIGH); // LED light is on
      } else {
         digitalWrite(ledPin, LOW);  // LED light is off
      }
    }

Program Effect:

FAQ

For any questions, advice or cool ideas to share, please visit the DFRobot Forum.

More Documents

DFshopping_car1.png Get LED Switch from DFRobot Store or DFRobot Distributor.

Turn to the Top