Generate a rectangular waveform with the specified duty and period.
rectangular-waveform
@/rectangular-waveform
Generate a rectangular waveform with the specified duty and period.
PORTport
Board port (pin) to write to (consult https://www.pjrc.com/teensy/td_libs_TimerOne.html to find out which ports are linked to timer one on your board).
DUTYnumber
Duty cycle value in range 0.0 … 1.0
Periodnumber
Period in microseconds. Will be rounded to an integer value.
UPDpulse
Update.
DONEpulse
Pulse on completion.
To use the node in your project you should have the wayland/rectangular-waveform 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/PaulStoffregen/TimerOne"
#include <TimerOne.h>
node {
void evaluate(Context ctx) {
static_assert(isValidDigitalPort(constant_input_PORT), "must be a valid digital port");
// The node responds only if there is an input pulse
if (!isInputDirty<input_UPD>(ctx))
return;
auto duty = getValue<input_DUTY>(ctx);
duty = duty > 1 ? 1 : (duty < 0 ? 0 : duty);
int val = (int)(duty * 1023);
unsigned long period = getValue<input_Period>(ctx);
Timer1.initialize(period);
Timer1.pwm(constant_input_PORT, val);
emitValue<output_DONE>(ctx, &Timer1);
}
}