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.
Last updated
Was this helpful?
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.
Last updated
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 .
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:
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:
On startup, set the hardware button’s LED to white and turn the other LED off!
Solution:
Make the LED light blue when a user presses the hardware button.
Solution:
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:
Solution:
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.