MrYsLab / s2a_fm

A Scratch Hardware Extension For Arduino
GNU General Public License v3.0
104 stars 64 forks source link

Floating point values #9

Closed davecraig closed 10 years ago

davecraig commented 10 years ago

Hi again,

Scratch2 starts using floating point at the drop of a hat, so if a user scales down an analog input (10 bit int) to an 8 bit value for PWM output the result is a floating point value. Scratch2 does have a 'round' function which can be used, but I think it would be good if s2a_fm also handled this. I had a quick look and the PWM case could be handled by changing line 454 of scratch_command_handlers.py from

            self.firmata.analog_write(pin, int(command[self.CMD_VALUE]))

to

            self.firmata.analog_write(pin, int(float(command[self.CMD_VALUE])))

There may be a more Python way of doing this, what do you think?

Thanks Dave