Figuring out how to make a buzzer node


#1

i wanted to make a buzzer node in xod but i cant figure out how to do so, because it needs to have different pitches, any ideas?


#2

Have you tried using a pwm node?


#3

Hello!

You can try to make a simple C++ wrapper node around Arduino’s tone and noTone. Something like:

// ... not checked draft ...

void evaluate(Context ctx) {
    auto port = getValue<input_PORT>(ctx);
    auto freq = getValue<input_FREQ>(ctx);
    auto enable = getValue<input_EN>(ctx);
    
    if (enable) {
        pinMode(port, OUTPUT);
        tone(port, freq);
    } else {
        noTone(port);
    }
}