Help with C++ , lost in the syntax

Hello, I’m trying to do something in C ++, I’ve copied parts from other nodes but I can not eliminate the error, if I try to solve it every time I have more.
The idea is to do a botton with debounce all in one, yes … the node is combined, but I want to learn something from C ++ :wink:
I appreciate your help

 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)) {
        emitValue<output_ERR>(ctx, 1);
        return;
        ::pinMode(port, INPUT);
    }

    State* state = getState(ctx); //error: conversion from 'xod::____button_mod::State*' to non-scalar type 'xod::____button_mod::
                                  //State' requested State state = getState(ctx);
                                  //                                           ^
    bool x = getValue<input_PORT>(ctx); // read digital port; is correct?

    if (x != state->state) { //error: base operand of '->' has non-pointer type 'xod::____button_mod::
                             //State'  if (x != state->state) {
                             //                      ^
        state->state = x;    //base operand of '->' has non-pointer type 'xod::____button_mod::State'
                             // state->state = x;
                             //      ^

        TimeMs dt = getValue<input_Ts>(ctx) * 1000;
        setTimeout(ctx, dt);
    }
    if (isTimedOut(ctx)) {
    ::pinMode(port, INPUT);
    emitValue<output_SIG>(ctx, ::digitalRead(!port));
    emitValue<output_DONE>(ctx, 1);
    }
}

I’m pretty sure the listing is somewhat damaged because the first error message does not reflect the actual code you’ve listed. Also, I’m not sure what are you trying to do with state->state. XOD C++ nodes is not the best place to start learning C++ because… it’s tricky, dirty, hacky C++.

I would happy to help in solving the problems of converting the “normal C++” to XOD C++, but explaining pointers will benefit no one.

What do you want to achieve with the node?

hello, made many mistakes, solved them compiled, but did not get the result.

I tried to put a debounce but it was not correct. The idea is to get this to work, I’m missing a bit already almost

How do I read a port and store it in a variable?

::digitalRead(port, .............

button-mod

Something like this?

// read and store in a one-off variable
bool state = digitalRead(port);
// “publish” on node output
emitValue<output_SIG>(ctx, state);
1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.