Book Image

Arduino BLINK Blueprints

By : Utsav Shah
Book Image

Arduino BLINK Blueprints

By: Utsav Shah

Overview of this book

Arduino is an open-source prototyping platform based on easy-to-use hardware and software. Arduino has been used in thousands of different projects and applications by a wide range of programmers and artists, and their contributions have added up to an incredible amount of accessible knowledge that can be of great help to novices and experts alike. Want to build exciting LED projects with Arduino? This book will be your companion to bring out the creative genius in you. To begin with, you will get introduced to the maker movement and the open source hardware development Arduino boards. You will then move on to develop a mood lamp and a remote-controlled TV backlight. As you progress through the book, you will develop an LED cube and will learn to use sound visualization to develop a sound-controlled LED Christmas tree. You will then move on to build a persistence of vision wand. At the end of each chapter, you’ll see some common problems, their solutions, and some workarounds.
Table of Contents (14 chapters)

Programming an LED array


An LED array is nothing but a few LEDs connected together. Usually, an LED array comes in sizes of eight LEDs and 16 LEDs. You can control an LED array directly using the digitalWrite() function. Apart from using the digitalWrite() function, you can control LEDs directly using port-level communication. On Arduino, we have three ports: ports B, C, and D:

  • Port B: Digital pins 8 to 13

  • Port C: Analog pins

  • Port D: Digital pins 0 to 7

Each port is controlled by three DDR registers. These registers are defined variables in Arduino as DDRB, DDRC, and DDRD. Using these variables, we can make the pins either as input or output in the setup function.

You can use the following syntax to initialize the pins:

DDRy = Bxxxxxxxx

Here, y is the name of the port (B/C/D) and x is the value of the pin that determines if the pin is input or output. We will use 0 for input and 1 for output. LSB (least significant byte) is the lowest pin number for that register.

To control pins using this port...