As a means to control the LEDs on the pepper, I have created a square function - based on the one at the oscillator library - in which pulse width is one of the arguments.
However, I get the error "no matching function for call to 'squarePWM'" when I use "context", and no output at all anyway when I use any number in the first argument.
I am attaching the code here:
#include <Bela.h>
#include <cmath>
#include <libraries/math_neon/math_neon.h>
#include <vector>
int fs;
float phase_;
float Width;
float out;
float frequency_;
float invSampleRate_ = 1 / fs;
std::vector<int> ledPins = {6, 7, 10, 2, 3, 0, 1, 4, 5, 8}; // Bela Pepper Pin Numbering
std::vector<float> analogInput(8);
void computePhase()
{
phase_ += 2.0f * (float)M_PI * frequency_ * invSampleRate_;
if(phase_ > M_PI)
phase_ -= 2.0f * (float)M_PI;
}
float squarePWM(int fs, float Width)
{
if(phase_ > Width)
{
out = 1;
}
else
{
out = 0;
}
computePhase();
return out;
}
bool setup(BelaContext *context, void *userData)
{
for(unsigned int i = 0; i < 10; i++)
{
pinMode(context, 0, ledPins[i], OUTPUT);
}
return true;
}
void render(BelaContext *context, void *userData)
{
for(unsigned int n = 0; n < context->analogFrames; n++)
{
for(unsigned int m = 0; m < 8; m++)
{
analogInput[m] = analogRead(context, n, m);
}
}
for(unsigned int n = 0; n < context->digitalFrames; n++)
{
for(unsigned int m = 0; m < 2; m++)
{
digitalWriteOnce(context, n, ledPins[m], squarePWM(context, analogInput[0]));
}
for(unsigned int m = 2; m < 8; m++)
{
digitalWriteOnce(context, n, ledPins[m], squarePWM(context, analogInput[m - 1]));
}
for(unsigned int m = 8; m < 10; m++)
{
digitalWriteOnce(context, n, ledPins[m], squarePWM(context, analogInput[7]));
}
}
}
void cleanup(BelaContext *context, void *userData)
{
}
Please let me know if I am missing something here : ) Thank you.