pulse-in

robertspark/components/pulse-in

Reads a pulse (either HIGH or LOW) on a pin. For example, if value is HIGH, pulseIn() waits for the pin to go HIGH, starts timing, then waits for the pin to go LOW and stops timing. Returns the length of the pulse in microseconds or 0 if no complete pulse was received within the timeout. The timing of this function has been determined empirically and will probably show errors in shorter pulses. Works on pulses from 10 microseconds to 3 minutes in length. Please also note that if the pin is already high when the function is called, it will wait for the pin to go LOW and then HIGH before it starts counting. This routine can be used only if interrupts are activated. Furthermore the highest resolution is obtained with large intervals.
pulse-in
@/pulse-in
Reads a pulse (either HIGH or LOW) on a pin. For example, if value is HIGH, pulseIn() waits for the pin to go HIGH, starts timing, then waits for the pin to go LOW and stops timing. Returns the length of the pulse in microseconds or 0 if no complete pulse was received within the timeout. The timing of this function has been determined empirically and will probably show errors in shorter pulses. Works on pulses from 10 microseconds to 3 minutes in length. Please also note that if the pin is already high when the function is called, it will wait for the pin to go LOW and then HIGH before it starts counting. This routine can be used only if interrupts are activated. Furthermore the highest resolution is obtained with large intervals.
PORTport
Board port to read from
H/Lboolean
High (true) or Low (false) Pulse Measure
m/uboolean
Output time in MilliSeconds (true) or MicroSeconds (false)
UPDpulse
Triggers new read
pulse-in
TIME
DONE
PORT
H/L
m/u
UPD
DONEpulse
Fires on reading complete
TIMEnumber
The length of the pulse (in microseconds) or 0 if no pulse started before the timeout.
To use the node in your project you should have the robertspark/components library installed. Use the “File → Add Library” menu item in XOD IDE if you don’t have it yet. See Using libraries for more info.

C++ implementation

#pragma XOD error_raise enable

struct State {
};

{{ GENERATED_CODE }}

void evaluate(Context ctx) {
    if (!isInputDirty<input_UPD>(ctx))
        return;

    const uint8_t port = getValue<input_PORT>(ctx);
    if (!isValidDigitalPort(port)) {
        raiseError(ctx);
        return;
    }

    bool highLow = getValue<input_HU002FL>(ctx);
    uint8_t value = 0;
    if (highLow == 1)
    {
        value = 1;
    }
    else {
        value = 0;
    }

    bool mSecs = getValue<input_mU002Fu>(ctx);
    auto multi = 0.0;
    if (mSecs == 1)
    {
        multi = 0.001;
    }
    else {
        multi = 0.0;
    }

    emitValue<output_TIME>(ctx, pulseIn(port, value) * multi);
    emitValue<output_DONE>(ctx, 1);
}