Hi i am trying to find the correct reading for the mapping function using this code:
int flexSensorPin = A0; //analog pin 0
void setup(){
Serial.begin(9600);
}
void loop(){
int flexSensorReading = analogRead(flexSensorPin);
Serial.println(flexSensorReading);
int flex0to100 = map(flexSensorReading, 512, 614, 0, 100);
Serial.println(flex0to100);
delay(250); //just here to slow down the output for easier reading
}
I am using a flex sensor hooked up to a arduino fios and i cant seem to find the correct reding for the function.
when i test the code with the map function, the motors dont move or they twitch as opposed to following the sensors angle
i can post the code if needed
Just so I understand what you are saying...gives a negative number.
No. It's the map function that gives the negative number.
That happens when the input value (the first argument) is less than the second argument.
OP: Why are you using the from range values that you have? What actual range of values do you get from reading the flex sensor? Those are the values that should be the from range.
How do you expect to get 180 from map when you have the to range set to 0 to 100?