i2c-servo-pwm-device

bradzilla84/i2c-pwm-servo-16ch/i2c-servo-pwm-device

i2c Device. Uses the default address 0x40
i2c-servo-pwm-device
@/i2c-servo-pwm-device
i2c Device. Uses the default address 0x40
PWMFreqnumber
PWM frequency 0 to 1600
i2c-servo-pwm-device
DEV
PWMFreq
DEV@/i2c-servo-pwm-device
To use the node in your project you should have the bradzilla84/i2c-pwm-servo-16ch 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 require "https://github.com/adafruit/Adafruit-PWM-Servo-Driver-Library"
// Include C++ library:
{{#global}}
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
{{/global}}

struct State {
    uint8_t mem[sizeof(Adafruit_PWMServoDriver)];
};

// Define our custom type as a pointer on the class instance.
using Type = Adafruit_PWMServoDriver*;

{{ GENERATED_CODE }}

void evaluate(Context ctx) {
    // It should be evaluated only once on the first (setup) transaction
    if (!isSettingUp())
        return;

    auto state = getState(ctx);

    // Create a new object in the memory area reserved previously.
    Type pwm = new (state->mem) Adafruit_PWMServoDriver();
    pwm->begin();
    pwm->setPWMFreq(getValue<input_PWMFreq>(ctx));  // Analog servos run at ~60 Hz updates

    emitValue<output_DEV>(ctx, pwm);
}