Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
C Programming for Arduino

You're reading from  C Programming for Arduino

Product type Book
Published in May 2013
Publisher Packt
ISBN-13 9781849517584
Pages 512 pages
Edition 1st Edition
Languages
Author (1):
Julien Bayle Julien Bayle
Profile icon Julien Bayle

Table of Contents (21) Chapters

C Programming for Arduino
Credits
About the Author
Acknowledgement
About the Reviewers
www.PacktPub.com
Preface
Let's Plug Things First Contact with C C Basics – Making You Stronger Improve Programming with Functions, Math, and Timing Sensing with Digital Inputs Sensing the World – Feeling with Analog Inputs Talking over Serial Designing Visual Output Feedback Making Things Move and Creating Sounds Some Advanced Techniques Networking Playing with Max 6 Framework Improving your C Programming and Creating Libraries Index

Chapter 6. Sensing the World – Feeling with Analog Inputs

The real world isn't digital. My digital-art-based vision shows me The Matrix behind things and huge digital waterfalls between things. In this chapter, however, I need to convey to you the relationship between digital and analog, and we need to understand it well.

This chapter is a good one but a huge one. Don't be afraid. We'll also discuss new concepts a lot while writing and designing pure C++ code.

We are going to describe together what analog inputs are. I'm also going to introduce you to a new and powerful friend worthy of respect, Max 6 framework. Indeed, it will help us a bit like Processing did—to communicate with the Arduino board. You'll realize how important this is for computers, especially when they have to sense the world. A computer with the Max 6 framework is very powerful, but a computer with the Max 6 framework and the Arduino plugin can feel much characteristics of the physical world, such as pressure, temperature...

Sensing analog inputs and continuous values


There's no better way to define analog than by comparing it to digital. We just talked about digital inputs in the previous chapter, and you now know well about the only two values those kind of inputs can read. It is a bit exhausting to write it, and I apologize because this is indeed more a processor constraint than a pure input limitation. By the way, the result is that a digital input can only provide 0 or 1 to our executed binary firmware.

Analog works totally differently. Indeed, analog inputs can continuously provide variable values by measuring voltage from 0 V to 5 V. It means a value of 1.4 V and another value of 4.9 V would be interpreted as totally different values. This is very different from a digital input that could interpret them as…1. Indeed, as we already saw, a voltage value greater than 0 is usually understood as 1 by digital inputs. 0 is understood as 0, but 1.4 would be understood as 1; this we can understand as HIGH, the...

Introducing Max 6, the graphical programming framework


Now, let me introduce you to the framework known as Max 6. This is a whole universe in itself, but I wanted to write some pages about it in this book because you'll probably come across it in your future projects; maybe you'll be a Max 6 developer one day, like me, or perhaps you'll have to interface your smart physical objects with Max 6-based systems.

The following is one of the patches of my 3D universe project with Max 6:

A brief history of Max/MSP

Max is a visual programming language for multimedia purposes. It is actually developed and maintained by Cycling '74. Why call it Max? It was named after Max Matthews (http://en.wikipedia.org/wiki/Max_Mathews), one of the great pioneers of computer music.

The original version of Max was written by Miller Puckette; it was initially an editor named Patcher for Macintosh. He wrote it at The European Institut de Recherche et Coordination Acoustique/Musique (IRCAM), an avant-garde science institute...

Controlling software using hardware


Coming from pure digital realms where everything can be wrapped into software and virtual worlds, we often need physical interfaces. This can sound like a paradox; we want everything in one place, but that place is so small and user-unfriendly for everything related to pure creation and feelings that we need more or less big external (physical) interfaces. I love this paradox.

But, why do we need such interfaces? Sometimes, the old mouse and QWERTY keyboard don't cut it. Our computers are fast, but these interfaces to control our programs are slow and clunky.

We need interfaces between the real world and the virtual world. Whatever they are, we need them to focus on our final purpose, which is usually not the interface or even the software itself.

Personally, I write books and teach art-related technology courses, but as a live performer, I need to focus on the final rendering. While performing, I want to black-box as much as possible the technology under...

Multiplexing with a CD4051 multiplexer/demultiplexer


We are going to explore a technique called multiplexing . This is a major subchapter because we are going to learn how to make our real-life project more concrete, more real.

We often have many constraints in the real world. One can be the number of Arduinos available. This constraint can also come from having a computer that has only one USB port. Yes, this happens in real life, and I would be lying if I said you can have every connector you want, whenever you want, within the budget you want.

Imagine that you have to plug more than eight sensors to you Arduino's analog input. How would you do it?

We will learn to multiplex signals.

Multiplexing concepts

Multiplexing is quite common in the telecommunications world. Multiplexing defines techniques providing efficient ways to make multiple signals share a single medium.

Basic multiplexing concept showing the shared medium

This technique provides a very helpful concept in which you only need one...

Summary


In this chapter, we learnt at least how to approach a very powerful graphical framework environment named Max 6. We'll use it in several further examples in this book as we continue to use Processing too.

We learnt some reflexes for when we want to handle sensors providing continuous voltage variations to our Arduino analog inputs.

Then, we also discovered a very important technique, the multiplexing/demultiplexing.

We are going to talk about it in the next chapter about serial communication. We'll dig deeper into this type of communication now that we have used a lot of time already.

lock icon The rest of the chapter is locked
You have been reading a chapter from
C Programming for Arduino
Published in: May 2013 Publisher: Packt ISBN-13: 9781849517584
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}