Book Image

Mastering Arduino

By : Jon Hoffman
Book Image

Mastering Arduino

By: Jon Hoffman

Overview of this book

Mastering Arduino is an all-in-one guide to getting the most out of your Arduino. This practical, no-nonsense guide teaches you all of the electronics and programming skills that you need to create advanced Arduino projects. This book is packed full of real-world projects for you to practice on, bringing all of the knowledge in the book together and giving you the skills to build your own robot from the examples in this book. The final two chapters discuss wireless technologies and how they can be used in your projects. The book begins with the basics of electronics, making sure that you understand components, circuits, and prototyping before moving on. It then performs the same function for code, getting you into the Arduino IDE and showing you how to connect the Arduino to a computer and run simple projects on your Arduino. Once the basics are out of the way, the next 10 chapters of the book focus on small projects centered around particular components, such as LCD displays, stepper motors, or voice synthesizers. Each of these chapters will get you familiar with the technology involved, how to build with it, how to program it, and how it can be used in your own projects.
Table of Contents (23 chapters)

Analog write

Analog values are written to the Arduino with the Pulse-Width Modulation (PWM) pins. In Chapter 1The Arduino, we looked at what PWM is and how they work. On most Arduino boards the PWM pins are configured for pins 3, 5, 6, 9, 10, and 11; however, the Arduino Mega has significantly more pins available for PWM functionality.

To perform an analog write, we use the analogWrite() function, which takes the following syntax:

analogWrite(pin, value); 

The analogWrite() function accepts two parameters, where the first one is the pin number and the second is the value to set. The value for the analogWrite() function can range from 0 to 255.

Let's look at a sample sketch to see how we can use the analogWrite() function to fade a led in and out:

#define LED_ONE 11

int val = 0;
int change = 5;

void setup()
{
  pinMode(LED_ONE, OUTPUT);
}

void loop()
{
  val += change...