Skip to content

Pulse counting question #1374

Answered by phoddie
ethos-jgreenwood asked this question in Q&A
Jul 19, 2024 · 1 comments · 4 replies
Discussion options

You must be logged in to vote

Thank you for the additional details.

The monitor class expects to be used with an onChanged callback to notify the client when the counters change. The exception happens when the monitor attempts to report the change but there is no onChanged callback. Your code tries to do this, but uses the ECMA-419 API stye which isn't implemented by the older Monitor API. Something like this should work as you intend:

    this.#pinMonitor = new Monitor({
      pin: sensor_pin,
      mode: Digital.Input,
      edge: Monitor.Falling
    });
    this.#pinsMonitor.onChanged = function() {
        trace(`Pin monitor: ${this.falls}`);
    };

The documentation for the Monitor class describes this correctly.

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@ethos-jgreenwood
Comment options

@phoddie
Comment options

@ethos-jgreenwood
Comment options

@phoddie
Comment options

Answer selected by ethos-jgreenwood
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants