fast-analog-read

robertspark/faster-analog-read/fast-analog-read

Fast read of an analog signal value from board ADC port. Possible errors: — Invalid port
fast-analog-read
@/fast-analog-read
Fast read of an analog signal value from board ADC port. Possible errors: — Invalid port
PORTport
Analog port to read from. Should start with `A` to succeed.
UPDpulse
Triggers new read
0-1boolean
Sets the input to be between a range of 0-1 (if true) or RAW 0-1023
fast-analog-read
VAL
DONE
PORT
UPD
0-1
DONEpulse
Fires on reading complete
VALnumber
The latest read value in range 0 to 1023 ... OR if 0-1 set to true, the range will be 0-1
To use the node in your project you should have the robertspark/faster-analog-read 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

#pragma XOD require "https://github.com/robertspark/FastAnalogRead"

{{#global}}
#include <avdweb_AnalogReadFast.h>
{{/global}}

struct State {
};

{{ GENERATED_CODE }}

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

    const uint8_t port = getValue<input_PORT>(ctx);
    bool raw = getValue<input_0_1>(ctx);

    if (!isValidAnalogPort(port)) {
        raiseError(ctx);
        return;
    }

    if (raw == true) {
        emitValue<output_VAL>(ctx, analogReadFast(port) / 1023.);
        emitValue<output_DONE>(ctx, 1);
        return;
    }
    else{
        emitValue<output_VAL>(ctx, analogReadFast(port));
        emitValue<output_DONE>(ctx, 1);
    }
}