Ali
May 9, 2022, 4:22pm
#1
Hello,
I am new to the Daisy platform and a general coding noob. I am trying
to code a sequencer and use a pot to update the bpm. I am running into
issues where the pot seems stuck at one value when ever the audio callback
is running if i comment it out then the pot updates and prints properly to
serial monitor. Wondering if anyone can provide some insight to what
im doing wrong. Any help will be greatly appreciated. Thanks.
void MyCallback(float **in, float **out, size_t size) {
float sine, freq;
uint8_t tic;
sysclock.SetFreq(BPMHZ) ;
bpmpotread();
for (size_t i = 0; i < size; i++) {
tic = sysclock.Process();
if (tic && playstatehold == 1) {
debug();
currentstep++;
Tickcounter++;
if(Tickcounter >= TICKCOUNT ){
Tickcounter = 0;
Beatcounter++;
Beatcounterui++;
}
if(Beatcounter > Beatcount){
Beatcounter = 1;
}
if(Beatcounterui > BEATSPERBAR){
Beatcounterui = 1;
Barcounterui++;
}
if(Barcounterui > Bars){
Barcounterui =1;
}
//sets seq back to 0 after finishing
if (currentstep >= stepcount) {
currentstep = 0;
Beatcounter = 1;
}
if(laststep < 0){
laststep = stepcount;
}
if (laststep > stepcount){
laststep = 0;
}
}
}
}
void setup() {
// Initialize for Daisy pod at 48kHz
hw = DAISY.init(DAISY_SEED, AUDIO_SR_48K);
num_channels = hw.num_channels;
sysclock.Init(BPMHZ, SAMPLERATE / 96 );
//******************SET PIN MODES*******************
pinMode(bpmledpin, OUTPUT);
pinMode(recordledpin, OUTPUT);
pinMode(CH1out, OUTPUT);
pinMode(stoppin, INPUT_PULLUP);
pinMode(playpin, INPUT_PULLUP);
pinMode(pad1pin, INPUT_PULLUP);
pinMode(recordpin, INPUT_PULLUP);
pinMode(bpmpotpin, INPUT);
//begin serial monitor
Serial.begin(9600);
/** Start the audio callback */
DAISY.StartAudio(MyCallback);
}
void loop() {
hw.ProcessAllControls();
playstate();
}
/////// Void defs below here/////////
void bpmpotread(){
BPM = map(analogRead(bpmpotpin), 0, 1023, MINBPM, MAXBPM);
BPMHZ = BPM * 0.0166666666666667; //bpm to hz conversion
sysclock.SetFreq(BPMHZ);
}
void playstate(){
if(play.update()){
playstatehold = 1;
digitalWrite(playledpin,HIGH);
}
if(playstart.update()){
if(playstart.fallingEdge()){
playstatehold = 1;
Tickcounter = 0;
Beatcounter = 1;
Beatcounterui = 1;
Barcounterui = 1;
digitalWrite(playledpin,HIGH);
}
}
if(stopplay.update()){
playstatehold = 0;
recordstatehold = 0;
digitalWrite(playledpin,LOW);
digitalWrite(recordledpin,LOW);
}
else{playledstate = LOW;}
if (record.update()) {
if (record.fallingEdge() && recordstatehold == 0 ){
playstatehold = 1;
recordstatehold = 1;
recordledstate = HIGH;
;
}
else if (record.fallingEdge() && recordstatehold == 1){
recordstatehold = 0;
recordledstate = LOW;
}
}
}
void debug(){
Serial.print(Barcounterui);
Serial.print(" ");
Serial.print(Beatcounterui);
Serial.print(" ");
Serial.print(Tickcounter);
Serial.print(" ");
Serial.print("Step:");
Serial.print(currentstep);
Serial.print(" | ");
Serial.print(stepcount);
Serial.print(" ");
Serial.print(Beatcounter);
Serial.print(" OF ");
Serial.print(Beatcount);
Serial.print(" ");
Serial.print(ch1gate[Beatcounter][Tickcounter]);
Serial.print(" ");
Serial.print("Tempo:");
Serial.println(BPM);
if(recordstatehold == 1){
Serial.println("RECORDING ACTIVE");
}
}