Internet of Things
TinkerforgeCode in ActionAbout Me
  • Course Outline
  • 1 - Getting Started
    • Overview
    • Connect to the LED
    • Getting Started
      • Glitch
      • The Application Template
    • Concepts in Programming
      • What is Programming?
      • Variables
      • Functions and Commands
      • Control Structures
      • Loops
      • Objects and Libraries
    • Programming Simple Web Apps
    • Exercises
      • 1.1 Buttons and Inputs
  • 2 - Internet of Things
    • Overview
    • IoT in our Apps
      • Getting Started
        • Hardware Kit
        • Brick Viewer and Daemon
      • Connect to the Devices
        • The Tinkerforge Device Manager
      • Program the Devices
        • RGB LED
        • RGB LED Button
        • OLED Display
        • Sensors
          • Humidity Sensor
          • Ambient Light Sensor
    • Components and Use Cases
    • Exercises
      • 2.1 Lights and Buttons
      • 2.2 Sensors
      • 2.3 Display
  • 3 - Artificial Intelligence
    • Overview
    • AI in our Apps
      • Google's Teachable Machine
      • Face Recognition
      • Training a Custom Model
    • Rules vs. Learning
    • Learning from Data
    • Use Cases
      • Computer Vision
        • Image Classification
        • Handwriting Recognition
    • Machine Learning Algorithms
      • Artificial Neural Networks
      • Decision Trees
      • Logistic Regression
    • Exercises
      • 3.1 Rules vs. Learning
      • 3.2 Fruits and Vegetables
      • 3.3 Face Recognition
      • 3.4 A Classifier for Iris
  • 4 - Cloud & APIs
    • Overview
    • APIs in our Apps
    • Cloud and APIs
      • Weather API
      • NASA Open APIs
      • EDAMAM Nutrition and Recipes API
    • Push Notifications
    • Exercises
  • 5 - App Project
    • Overview
    • Summer 2021
    • Summer 2022
  • Appendix
    • Other Devices
      • Motorized Linear Poti
      • Sound Pressure Sensor
      • NFC Reader
      • Motion Detector
    • UI Features
      • Realtime Charts
      • Countdown Timer
    • Digital Computers
      • Overview
      • The Binary System
      • Code Systems
      • Logic Gates
      • Binary Addition
      • From Analog to Digital
    • Cheat Sheets
    • Projects
      • IoT @ Pickup-Boxes
Powered by GitBook
On this page
  • Goals
  • Get the LED
  • Set the color of the LED
  • Turning the LED off
  • Let the LED blink in a color

Was this helpful?

  1. 2 - Internet of Things
  2. IoT in our Apps
  3. Program the Devices

RGB LED

PreviousProgram the DevicesNextRGB LED Button

Last updated 4 years ago

Was this helpful?

Goals

  • You know how to get a handle on the LED connected to your computer

  • You can set the color of the LED, turn it on and off, and make it blink

Get the LED

Using the in our program is straightforward. In this article, we assume you have successfully initialized the devices with the , and you stored all connected devices on a global variable devices. We also declared a global variable led.

Next, we need to know the device identifier of the RGB LED, which is 271:

// Get a reference to the LED and store in on the global variable
led = devices.getDeviceByIdentifier(271);

Now that we have a reference to the LED on the variable led, we can use that variable to call the LED's functions.

Set the color of the LED

With setColor() we can turn the LED on and specify the color of the light. We define the color using the RGB notation:

// Set the LED to red
led.setColor(255, 0, 0);

// Set the LED to green
led.setcolor(0, 255, 0);

Turning the LED off

We can turn the LED off (black) at any time with the shortcut function off():

// Turn the LED off
led.off();

Let the LED blink in a color

Similar to setting the color, we can use blink() to make the LED blink at a given frequency:

// Make the LED blink in green at a 500 ms interval
led.blink(0, 255, 0, 500);

That's it, we can't do more with an .

RGB LED
Tinkerforge Device Manager
RGB LED