Hi everyone!
I have a project where I basically receive MIDI over USB to set digital potis over SPI. I've attached the (shortened) code below.
My problem is that there is a delay of about a whole second between sending the MIDI CC command (I'm using SuperCollider for this) and the reaction of the digital potentiometer. I can't really imagine that it's because of the SPI interface because there's very few code involved (there are no delay() calls or anything involved in the Mcp4261-class I use).
Now I also don't really know what my options are to debug this. Any tips?
Thanks,
Benni.
I have a project where I basically receive MIDI over USB to set digital potis over SPI. I've attached the (shortened) code below.
My problem is that there is a delay of about a whole second between sending the MIDI CC command (I'm using SuperCollider for this) and the reaction of the digital potentiometer. I can't really imagine that it's because of the SPI interface because there's very few code involved (there are no delay() calls or anything involved in the Mcp4261-class I use).
Now I also don't really know what my options are to debug this. Any tips?
Thanks,
Benni.
Code:
// This example demonstrates control over SPI to the Microchip MCP4261 Digital potentometer
// SPI Pinouts are for Arduino Uno and Arduino Duemilanove board (will differ for Arduino MEGA)
// Download these into your Sketches/libraries/ folder...
#include <Arduino.h>
#include <SPI.h>
// Mcp4261 library available from https://github.com/dreamcat4/Mcp4261
#include <Mcp4261.h>
#define POTI_1_PIN 0
float poti1_ohms = 101550.00;
// and measure those
float poti1_wiper = 115;
MCP4261 potis[] = {
MCP4261(POTI_1_PIN, poti1_ohms, poti1_wiper)
};
void setup()
{
SPI.begin();
potis[0].scale = 127; // scale to midi values
potis[0].wiper0(0);
potis[0].wiper1(0);
usbMIDI.setHandleControlChange(OnControlChange);
}
float lastMillis = 0;
void loop() {
usbMIDI.read();
}
void OnControlChange(byte channel, byte control, byte value) {
int wiperNum = control%2;
if(wiperNum == 0) {
potis[0].wiper0((int)value);
} else {
potis[0].wiper1((int)value);
}
}