hardbap / firmata

A Ruby implementation of the Firmata protocol.
MIT License
42 stars 23 forks source link

No reason to set analog reporting #3

Closed hardbap closed 11 years ago

hardbap commented 11 years ago

[This is from an email from Steven Morss]

In board.rb, you have a toggle_pin_reporting() method which turns on/off the reporting for all the analog and digital ports. For the digital ports, this is OK, since they only report on change, so you won't get flooded with events. The analog ports report every sampling interval, which defaults to about 50 times per second. For 16 ports (on the Mega for instance), that can be a lot of samples. More importantly, if the pins are not in analog mode (they can be in digital mode), reading them back only gives back bad data, so they shouldn't be sampled. An easier way to handle things is not to set the report bits on the analog ports at all. In the Arduino C code, when a port is set to analog/digital mode, it's analog report bit is set/cleared automatically (see setPinModeCallback) in the Firmata code. So setting the analog polling bits is done already - no need to do it again