read-channel

amperka/octoliner/read-channel

Reads the tint value from a certain channel of the Octoliner board.
read-channel
@/read-channel
Reads the tint value from a certain channel of the Octoliner board.
IN@/octoliner-device
CHnumber
A channel number ro read from in the range [0,7].
UPDpulse
Triggers a new read.
read-channel
OUT
IN
VAL
OK
CH
UPD
OKpulse
Fires if a reading is done.
VALnumber
The last tint value read from the specified channel in the range [0,1] where 0 is pure white and 1 is pure black.
OUT@/octoliner-device
To use the node in your project you should have the amperka/octoliner 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

struct State {
    const uint8_t sensorPinMap[8] = { 4, 5, 6, 8, 7, 3, 2, 1 };
    const uint8_t ADCResolution = 10;
};

// clang-format off
{{ GENERATED_CODE }}
// clang-format on

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

    auto state = getState(ctx);
    auto octoliner = getValue<input_IN>(ctx);

    uint8_t channel = getValue<input_CH>(ctx);
    channel &= 0x07;

    auto value = octoliner->analogRead(state->sensorPinMap[channel]);

    emitValue<output_VAL>(ctx, value / pow(2,state->ADCResolution));
    emitValue<output_OUT>(ctx, octoliner);
    emitValue<output_OK>(ctx, 1);

}