map function
any ideas why negative values out of this: code: [select] long a; long b; void loop() { while(true){ delay(1000); for (int = 0; < 255; i++){ a = pow(i,3); b = map(a, 0,pow(255,3), 0,300 ); ... ... ... i print b on lcd. starts run nocely after 127 turns negative , starts run closer 0. regards orbitrek it's somewhere in implementation of de map() function, integer overflow occuring. if don't need negative numbers being fed map(), might want use adapted method: code: [select] unsigned long mymap(unsigned long x, unsigned long in_min, unsigned long in_max, unsigned long out_min, unsigned long out_max) { return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; } i think solve problem. Arduino Forum > Forum 2005-2010 (read only) > Software ...