Ohhhhhhhhhhhhhhhh. So the problem is with the map function. ![]()
Well, map can't handle very large numbers, because...
long map(long x, long in_min, long in_max, long out_min, long out_max) {
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
...the first multiplication overflows a long.
You could try rolling your own. Give this a try:
long largeMap(long x, long in_min, long in_max, long out_min, long out_max) {
return ((x - in_min) / (in_max - in_min)) * (out_max - out_min) + out_min;
}
Other ideas here: "map" function and large numbers - #11 by robtillaart