Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

4
  • Serial.print(valor / 700.0f * 255); would work better. 700.0 is a double not a float and so by the rules of the c language that entire calculation is done as doubles. Adding that f in turns it into a float. On a low end microcontroller you really want to avoid doubles as much as possible, double operations are twice as slow as a floats and floats are slow enough already. Commented Dec 6, 2016 at 10:12
  • 1
    @Andrew: The OP is working on an Uno. A double is the same as a float on the AVRs. Commented Dec 6, 2016 at 10:41
  • That in this particular case the standards aren't followed and so it doesn't make a difference isn't a good justification for inefficient coding. Pressing 1 extra key is a small price for a good habit and portable efficient code. Commented Dec 6, 2016 at 10:49
  • Not meaning to nitpick but I'd just point out that mapping floats to doubles on the UNO is a software choice implemented in the gnu compilers, not hardware-driven at all as the hardware has no support for floating point. A different tool-set might well implement a different choice. So could a programmer using gnu for that matter, by defining an 'sfloat' (small- or single-precision float) object and its arithmetic operators. Commented Dec 6, 2016 at 21:13