Book Image

C Programming for Arduino

By : Julien Bayle
Book Image

C Programming for Arduino

By: Julien Bayle

Overview of this book

Physical computing allows us to build interactive physical systems by using software & hardware in order to sense and respond to the real world. C Programming for Arduino will show you how to harness powerful capabilities like sensing, feedbacks, programming and even wiring and developing your own autonomous systems. C Programming for Arduino contains everything you need to directly start wiring and coding your own electronic project. You'll learn C and how to code several types of firmware for your Arduino, and then move on to design small typical systems to understand how handling buttons, leds, LCD, network modules and much more. After running through C/C++ for the Arduino, you'll learn how to control your software by using real buttons and distance sensors and even discover how you can use your Arduino with the Processing framework so that they work in unison. Advanced coverage includes using Wi-Fi networks and batteries to make your Arduino-based hardware more mobile and flexible without wires. If you want to learn how to build your own electronic devices with powerful open-source technology, then this book is for you.
Table of Contents (21 chapters)
C Programming for Arduino
About the Author
About the Reviewers

Improving the sound engine with Mozzi

The bit-banging technique is very cheap and it's nice to learn how it works. However, I can quote some annoying things here:

  • No pure sound: Square waves are a sum of all odd harmonics at the fundamental frequency

  • No amplitude control available: Each note sounds at the same volume

We are going to use a very nice library called Mozzi, by Tim Barrass. The official website is directly hosted on GitHub at It includes the TimerOne library, a very fast timer handler.

Mozzi provides a very nice 16,384 kHz, 8-bit audio output. There is also a nice basic audio toolkit containing oscillators, samples, lines and envelopes, and filtering too.

Everything is available without external hardware and by only using two pins of the Arduino.

We are going to design a small sound engine based on it.

Setting up a circuit and Mozzi library

Setting up the circuit is easy; it is the same as the latest one except that pin 9 has to be used.

Mozzi's documentation...