Chapter 2. Blink with Arduino
When you learn a new programming language, the first exercise is usually to display “Hello, World!” on a screen. When working with a new embedded device, the equivalent first exercise is to blink a light, often an LED. By toggling an LED, you check that the main parts of a system are working and that you can control them. Arduinos are famous for letting users get LEDs to blink very easily. Because it’s easy to get up and running with Arduino, you’ll be able to quickly get a feel for where and why JavaScript can be used in an embedded system.
To begin, what does it take to toggle an LED on and off? From a hardware perspective, most boards with a microcontroller have LEDs for debugging built in. And from a JavaScript viewpoint, controlling the blink of an LED can be as simple as:
led
.
toggle
();
However, to run this code, you need to set up the hardware. If you want to control an external LED, you must build a small electronic circuit. Depending on which board you use, you might need to configure a toolchain and connect a special device called a “programmer” to flash the board—JavaScript is the easy part.
Starting with an Arduino is very helpful in exploring the building blocks of a simple embedded device. For this, you must set up the pins of a microcontroller unit and build basic electronic circuits. Understanding the building blocks and their configurations can be challenging.
For this reason, we will begin with a discussion with Arduino. Broadly speaking, ...
Get Node.js for Embedded Systems now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.