Hi,
So I have a korg Volca beats, great but no swing/shuffle, been trying to solve the problem with the Arduino.
I've got an Arduino Sketch that sends out PWM blips in time controlled by a pot, based on some metronome code knocking around here, and it works fine moving the korg clock along.
Trying to adapt it so I can get some swing sounds out of it. I have two pots, one for BPM, one for swing amount.
My problem is thinking about how to offset every other click by a small amount of time, instead of pulsating an equal amount of time each tick, I think I need to cycle back and fourth between two varying interval lengths.
ie interval1, interval2 = interval1 + offset.
Offset is controlled by a pot, if pot = 0 then the interval is same length as the first, if it's 1023 then interval+offsettime.
I've tried it with this code, but it's really hacky and buggy and not sure my thinking is legit! Can anyone think of a better way of going about this?
const int ledPin = 13; // the number of the LED pin
const int pwmPin = 6;
const int analogInPin = A0; // read pot for tempo value
const int analogInPin2 = A1; // read pot for swing value
int ledState = LOW;
long previousMillis = 0;
long interval1 = 1000; // interval at which to blink (milliseconds)
long interval2 = 1000;
int tempo;
int sensorValue = 0;
int swingValue = 0;
int swingVal = 0;
void setup() {
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
}
void loop()
{
sensorValue = analogRead(analogInPin);
swingValue = analogRead(analogInPin2);
tempo = map(sensorValue, 0, 1023, 80, 420); //map in the range of 40 to 210 BPM
swingVal = swingValue; // does this need scaling? like with tempo
float interval1 = (1000/tempo)*60/2; //algorithm to convert tempo into BPM
float interval2 = interval1 + swingVal;
unsigned long currentMillis = millis();
if(currentMillis - previousMillis > interval1) {
// save the last time you blinked the LED
previousMillis = currentMillis;
// if the LED is off turn it on and vice-versa:
if (ledState == LOW)
ledState = HIGH;
else
ledState = LOW;
// delay(swingVal);
// set the LED with the ledState of the variable:
digitalWrite(ledPin, ledState);
digitalWrite(pwmPin, ledState);
}
if(currentMillis - previousMillis > interval2) {
// save the last time you blinked the LED
previousMillis = currentMillis;
// if the LED is off turn it on and vice-versa:
if (ledState == LOW)
ledState = HIGH;
else
ledState = LOW;
// delay(swingVal);
// set the LED with the ledState of the variable:
digitalWrite(ledPin, ledState);
digitalWrite(pwmPin, ledState);
}
}

