Questions tagged [map]
17 questions
7
votes
4 answers
What's the most efficient implementation of map(x,0,1023,50,250)?
I recently noticed how the map() function in Arduino was bulky in both terms of flash space used and time taken to execute, largely because it deals with long and involves a division and multiplication.
Many times you can replace maps with more…
Cybergibbons
- 5,420
- 7
- 34
- 51
4
votes
2 answers
Why is the constrain function used after the map function?
I am reading some sample code and they use this method of mapping data from IR sensors:
sensor1 = analogRead(0);
adj_1 = map(sensor1, s1_min, s1_max, 0, 255);
adj_1 = constrain(adj_1, 0, 255);
What is the point of using constrain here if…
Michael Rader
- 326
- 2
- 5
- 17
2
votes
1 answer
How can I compensate for a joysticks offset value in neutral position?
I have a joystick that outputs the values 0 - 4095. I want to map these values in this fashion (Yes, the reversed mapping is intended):
outputValue = map(inputValue, 4095, 0, -2048, 2047);
However, the neutral central position of the joystick is…
Erik
- 271
- 1
- 15
2
votes
1 answer
Arduino std::map returning random values
I'm working with an arduino UNO. I would like to be able to send it set and get commands over serial and have it update class data class members accordingly by key value pair. I spoke to users in the cpp room, and they suggested I try using map to…
ex080
- 23
- 1
- 5
2
votes
3 answers
Arduino starter kit servo is shaking
In the example of the arduino starter kit the point is to use a potenciometer to control a servo.
The code is
angle = map(potVal, 0, 1023, 0, 179);
The output in the serial
potVal: 1023, angle: 179
potVal: 1015, angle: 177
potVal: 1023, angle:…
blfuentes
- 221
- 2
- 7
- 18
2
votes
2 answers
Explanation of the formula of the map funtion
Can someone please explain (mathematically) how the formula for the map function actually came to light?
I have given the code of the map function below. You can see that it uses a formula to "map" values in a given range from a certain range. I…
Arafe Zawad Sajid
- 23
- 1
- 1
- 3
2
votes
2 answers
Is it possible to transmit Longitude and Latitude via RF433MHz?
I want to make a drone project, and to that I will use arduino as the platform. My plane is to use a Play Station controller to control the Drone in the air. In addition to that I want to connect a GPS-module. My question goes, is it possible to…
AdiT
- 125
- 1
- 1
- 4
1
vote
1 answer
WS2812b - Interpolate pixels on neopixel matrix with mask
simplified my goal is to display a transitional Background and some shapes. This shapes are not moving hard rasterized by 1 pixel, more like .1 each cycle. So I need a way to interpolate the movement between the surrounding Neopixels.
Background…
AngelOfEffekt
- 21
- 4
1
vote
2 answers
How do i make this map() application work as intended?
I want to map the value range 0-63 like this:
x y
0-15 = 0
16-31 = 1
32-47 = 2
48-63 = 3
However, using map function y = map(x, 0, 63, 0, 3); returns:
x y
0-15 = 0
16-31 = 0
32-47 = 1
48-63 = 2
Is this due to truncating fractions, or…
Erik
- 271
- 1
- 15
1
vote
4 answers
How to boil down analog input to just three cases?
I am investigating the use of a 3-position-switch for one of my projects to switch between different settings using just one analog input pin. For the three positions I am using ground/0V, ~2.5V (via 2x10k voltage divider) and full 5V. I am doing…
fertchen
- 37
- 8
0
votes
1 answer
Code for mapping voltage on a sensor and outputting a value in liters
I got a Resistive sender fuel gauge sketch off the internet that I have adapted. The Resistive sender is a floating magnet that activates read switches to vary the resistance. Using a stable 5v power source and 100-ohm resistor I have a voltage…
SV Savannah
- 167
- 9
0
votes
1 answer
Does the map() function works on an ATtiny85?
I have a working project on Arduino Uno.Now I want to shrink my project using an ATtiny85. Before purchasing an waiting for the shipment to arrive, I want to make sure that my whole code will run on ATtiny85.
specialy, will the map() function which…
Malith
- 103
- 4
0
votes
0 answers
Where are the Arduino Function Unit Tests kept? I want to submit a fix for a faulty Arduino function
I have coded a fix for a major problem with the Arduino map function (in Arduino.h & arduino/avr/cores/arduino/WMath.cpp).
I submitted it as a comment to map function causes huge errors when mapping to small intervals due to integer truncation…
brewmanz
- 155
- 4
0
votes
1 answer
Mapping values from analog input giving unexpected values?
Mega 2560
I am reading in values from 3 pots then mapping them to values between 0 - 255
#define REDPIN 7
#define GREENPIN 8
#define BLUEPIN 9
int red_pot = A0; // analog pin used to connect the potentiometer
int green_pot = A1;
int blue_pot …
DrBwts
- 161
- 1
- 9
0
votes
1 answer
Fade LED strip using proximity and map() function
I'm using a sonar sensor to detect proximity, and need to control the brightness of an LED strip in direct relationship to the distance detected. For example, as someone moves toward the sonar, the strip needs to dim.
I'm using map() to do it now…
claudybee
- 27
- 3