Hey there,
this is my first post. Glad to be here!
Disclaimer: I’m pretty new to C++ and programming in general so please go easy on me
I made modifications to the patch/Sequencer example. I want to be able to control the maxSteps with the first dial/control on the Daisy Patch. But when I try to read the value from that dial I can’t get the code to compile w/o errors.
This is the way I am trying to get the value (maxSteps is of int type):
maxSteps = static_cast<int>(patch.controls[1].Process);
See full code below.
Thanks in advance for your help!
Code
#include "daisysp.h"
#include "daisy_patch.h"
#include <string>
using namespace daisy;
using namespace daisysp;
DaisyPatch patch;
int values[8];
bool trigs[8];
int stepNumber;
bool trigOut;
int menuPos;
bool inSubMenu;
int maxSteps {8};
void UpdateControls();
void UpdateOled();
void UpdateOutputs();
int main(void)
{
patch.Init(); // Initialize hardware (daisy seed, and patch)
//init global vars
stepNumber = 0;
trigOut = false;
menuPos = 0;
inSubMenu = false;
for(int i = 0; i < 8; i++)
{
values[i] = 0.f;
trigs[i] = false;
}
patch.StartAdc();
while(1)
{
UpdateControls();
UpdateOled();
UpdateOutputs();
}
}
void UpdateControls()
{
patch.ProcessAnalogControls();
patch.ProcessDigitalControls();
//encoder
//can we simplify the menu logic?
if(!inSubMenu)
{
menuPos += patch.encoder.Increment();
menuPos = (menuPos % (maxSteps*2) + (maxSteps*2)) % (maxSteps*2);
if(menuPos < maxSteps)
{
inSubMenu = patch.encoder.RisingEdge() ? true : false;
}
else
{
trigs[menuPos % 8] = patch.encoder.RisingEdge()
? !trigs[menuPos % maxSteps]
: trigs[menuPos % maxSteps];
}
}
else
{
values[menuPos] += patch.encoder.Increment();
values[menuPos] = values[menuPos] < 0.f ? 0.f : values[menuPos];
values[menuPos] = values[menuPos] > 60.f ? 60.f : values[menuPos];
inSubMenu = patch.encoder.RisingEdge() ? false : true;
}
` maxSteps = static_cast<int>(patch.controls[1].Process);`
//gate in
if(patch.gate_input[0].Trig() || patch.gate_input[1].Trig())
{
stepNumber--;
if (stepNumber < 0)
stepNumber = maxSteps-1;
stepNumber = (stepNumber % maxSteps + maxSteps) % maxSteps;
trigOut = trigs[stepNumber];
}
}
void UpdateOled()
{
patch.display.Fill(false);
std::string str = "!";
char* cstr = &str[0];
patch.display.SetCursor(16 * stepNumber, 45);
patch.display.WriteString(cstr, Font_7x10, true);
//values and trigs
for(int i = 0; i < maxSteps; i++)
{
sprintf(cstr, "%d", values[i]);
patch.display.SetCursor(i * 16, 10);
patch.display.WriteString(cstr, Font_7x10, true);
str = trigs[i % maxSteps] ? "X" : "O";
patch.display.SetCursor(i * 16, 30);
patch.display.WriteString(cstr, Font_7x10, true);
}
//cursor
str = inSubMenu ? "@" : "o";
patch.display.SetCursor((menuPos % maxSteps) * 16, (menuPos > (maxSteps-1)) * 20);
patch.display.WriteString(cstr, Font_7x10, true);
patch.display.Update();
}
void UpdateOutputs()
{
patch.seed.dac.WriteValue(DacHandle::Channel::ONE,
round((values[stepNumber] / 12.f) * 819.2f));
patch.seed.dac.WriteValue(DacHandle::Channel::TWO,
round((values[stepNumber] / 12.f) * 819.2f));
dsy_gpio_write(&patch.gate_output, trigOut);
trigOut = false;
}
Error
Sequencer.cpp:81:35: error: cannot convert 'daisy::AnalogControl::Process' from type 'float (daisy::AnalogControl::)()' to type 'float'
81 | ctrl1_val = patch.controls[1].Process;