firmata / firmata.js

JavaScript implementation of the Firmata protocol
710 stars 147 forks source link

How to clear the analogRead listener of a pin? #223

Closed yuredev closed 4 years ago

yuredev commented 4 years ago

The function sent to the analogRead is ever called, but i need to clear this listener in a specific moment of my application

board.analogRead(0, (value) => {
  ...
});

Is there a way to clear the analogRead listener of a specific pin? something like: board.stopAnalogRead(0)?

dtex commented 4 years ago

From the docs

"To stop reporting analog values for a pin, call board.reportAnalogPin(analogPinNumber, 0). To restart, call analogRead(pin,callback) or use board.reportAnalogPin(analogPinNumber, 1) if you don't want to call analogRead again."

Is that what you needed?

yuredev commented 4 years ago

Yeah is this what i needed, Thank you very much!!