opto-sensors

gabbapeople/lab-1-sensors-1/opto-sensors

No description
opto-sensors
@/opto-sensors
P0port
P1port
UPDpulse
opto-sensors
P0
P1
UPD
EV0
EV1
EV1pulse
EV0pulse
To use the node in your project you should have the gabbapeople/lab-1-sensors-1 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

nodespace {

    volatile bool event0 = false;
    volatile bool event1 = false;

    void interrupt0Handler() {
            event0 = true;
    }
    void interrupt1Handler() {
            event1 = true;
    }
}

node {
    void evaluate(Context ctx) {

        if (isSettingUp()) {
            ::pinMode(constant_input_P0, INPUT_PULLUP);
            ::pinMode(constant_input_P1, INPUT_PULLUP);
            attachInterrupt(digitalPinToInterrupt(constant_input_P0), interrupt0Handler, FALLING);
            attachInterrupt(digitalPinToInterrupt(constant_input_P1), interrupt1Handler, RISING);
        }


        if (!isInputDirty<input_UPD>(ctx))
            return;

        if (event0) {
            event0 = false;
            emitValue<output_EV0>(ctx, 1);
        }
        if (event1) {
            event1 = false;
            emitValue<output_EV1>(ctx, 1);
        }
    }
}