I'm trying to hook up a DS04-NFC continuous servo (datasheet) and control it using my bela mini. I stripped down the bicolor-LED example and I'm doing an extremely primitive square wave where I lift output to high for a few ms and write it low for the rest of the 20ms period.
simplest version of my code:
bool setup(BelaContext *context, void *userData) {
pinMode(context, 0, 12, OUTPUT);
return true;
}
void render(BelaContext *context, void *userData) {
for (unsigned int n = 0; n < context->digitalFrames; ++n) {
static unsigned int count = 0;
int value = count <= 85 ? 1 : 0; // 1.9ms, clockwise
digitalWriteOnce(context, n, 12, value);
count++;
if (count == 882)
count = 0;
}
}
Unfortunately I can't get this code to work even though it's so stripped down. I've thought about setting up I2C to get the sensor data I need from bela into my arduino for the servo control, since I've got it working there, or setting up puredata for my project, but for now I've stayed in C++ land.