Am I using map() wrong? [[SOLVED]]

I’m trying to map the values of some photoresistors from 1-1023 to 1-100. For some reason though, I’m getting values up to 200 and higher. Am I doing this wrong?

int lightVal_1 = analogRead(pr1);
lightVal_1 = map(lightVal_1, 0, 1023, 0, 100);  

int lightVal_2 = analogRead(pr2);
lightVal_2 = map(lightVal_2, 0, 1023, 0, 100);

You’re doing the right thing. The max analog value is 4095 so use that value instead of 1023 in map.

Why thank you!

1 Like

Hmm… well strangely I am getting a range from 0 to 400 now instead of 100. The only thing I changed was the 1023 to 4095.

Wait again… now its working just fine! You know what, I’mma chalk that up to user error and call this case solved lol.

1 Like