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
  • a) Light up the LED
  • b) Make the LED blink
  • c) Initialize the LEDs on startup
  • d) Hardware button activates the LED
  • e) Hardware button toggles the LED
  • f) Random colors
  • g) Sequence of colors

Was this helpful?

  1. 2 - Internet of Things
  2. Exercises

2.1 Lights and Buttons

In this challenge, we’ll involve some electronic devices that are connected to our computer. We’ll try to build something fun out of an LED light and a button that can also shine in any color.

PreviousExercisesNext2.2 Sensors

Last updated 3 years ago

Was this helpful?

Make a copy of the for each of the tasks below and write the necessary code with JavaScript and HTML to solve the tasks below. Make sure you connected the to your computer's USB port, and you tested the correct functionality of the devices with the .

a) Light up the LED

We start easy! When the user presses the button on the website, make the LED light up in a green color! Next, change the program, so it lights the LED in your favorite color!

Solution:

b) Make the LED blink

Now, make the LED blink red when the user presses the button on the website. Let the user enter the frequency in milliseconds. Add a button to stop the LED from blinking.

Solution:

c) Initialize the LEDs on startup

On startup, set the hardware button’s LED to white and turn the other LED off!

Solution:

d) Hardware button activates the LED

Make the LED light blue when a user presses the hardware button.

Solution:

e) Hardware button toggles the LED

Now, when the user presses the hardware button again, turn the LED light off. Basically, make the button a switch for the LED light.

Solution:

f) Random colors

Solution:

g) Sequence of colors

Solution:

Enhance the program from and let the LED change randomly between the colors green, red, blue, and orange when a user presses the hardware button. (The button doesn’t turn the LED off anymore, it changes the light’s color randomly).

Change the program from and, which each button press, change the LED's color in a defined sequence of white, yellow, green, blue, and red. The change of color should no longer be random.

e)
f)
application template
hardware kit
Brick Viewer
Exercise 2.1 - Lights and Buttons | a) Light up the LED
Exercise 2.1 - Lights and Buttons | a) Make the LED blink
Exercise 2.1 - Lights and Buttons | a) Initialize LEDs on startup
Exercise 2.1 - Lights and Buttons | d) Hardware button activates the LED
Exercise 2.1 - Lights and Buttons | e) Hardware button toggles the LED
Exercise 2.1 - Lights and Buttons | f) Random colors
Exercise 2.1 - Lights and Buttons | f) Sequence of colors