Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Arduino Essentials

You're reading from   Arduino Essentials Enter the world of Arduino and its peripherals and start creating interesting projects

Arrow left icon
Product type Paperback
Published in Feb 2015
Publisher Packt
ISBN-13 9781784398569
Length 206 pages
Edition 1st Edition
Tools
Arrow right icon
Toc

Table of Contents (12) Chapters Close

Preface 1. Meeting the Arduino Family 2. The Arduino Development Environment FREE CHAPTER 3. Interacting with the Environment the Digital Way 4. Controlling Outputs Softly with Analog Outputs 5. Sensing the Real World through Digital Inputs 6. Analog Inputs to Feel Between All and Nothing 7. Managing the Time Domain 8. Communicating with Others 9. Dealing with Interrupts 10. Arduino in a Real Case – Greenhouse Control Index

The Arduino map function


Mapping a value from one range to another is a very simple thing. It's just a matter of finding which value will be at the same point of the output range as compared to the input range. Let's see it with a simple example.

If we have a possible input value of 0 to 100 and an allowed output range of 0 to 500 and we take a sample value of 75, we can say that it is at 75 percent of its input range, can't we? Well, which value will be at 75 percent of the output range, then? We will usually just make a simple correspondence:

Output Value = (Input Value x Maximum Output Value) / Maximum Input Value

Or, we will use the values in our example:

Output Value = (75 x 500) / 100 = 375

Here, 375 is just 75 percent of 500. Simple, isn't it?

It is so simple but also so common in the Arduino environment that we have a specific function to make this kind of mapping in the Arduino language, which is appropriately called the map() function.

As you can see by following the previous example...

lock icon The rest of the chapter is locked
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 €18.99/month. Cancel anytime