Hacky Swing/shuffle

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);
  }
}

you declare a global long here:

long interval1 = 1000;           // interval at which to blink (milliseconds)
long interval2 = 1000;

and then declare them again as floats here::

float interval1 = (1000/tempo)*60/2; //algorithm to convert tempo into BPM
float interval2 = interval1 + swingVal;

you don't need floats so you could change to:

interval1 = (1000L/tempo)*60/2; //algorithm to convert tempo into BPM// force the long result
interval2 = interval1 + swingVal;

you forgot to set mode pwmPin (a bad name for this pin unless you are using PWM, by the way)

digitalWrite(pwmPin, ledState);

try:

  Serial.begin(9600);
  pinMode(ledPin, OUTPUT);
  pinMode(pwmPin, OUTPUT);

you have this:

if (ledState == LOW)
      ledState = HIGH;
    else
      ledState = LOW;

how about just:

ledState = !ledState;

Hey Bulldog thanks!

I've changed it all to the ways you've suggested now, didn't realise it wasn't PWM, have changed the name to tickPin for reference.

Still seems to work fine pushing the clock signal along even though I thought it needed PWM, and I've used the analogWrite just now to control an Expression input on this guitar pedal I have, is that PWM?

I'm not entirely sure what's happening in this part:

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:
    ledState = !ledState;
     // delay(interval2);
    // set the LED with the ledState of the variable:
    digitalWrite(ledPin, ledState);
    digitalWrite(tickPin, ledState);
  }

Not sure how to alternate between using interval1 and interval2 for the ticks. Is there a clever piece of magic around this?

const int ledPin =  13; // the number of the LED pin
const int tickPin =  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);
  pinMode(tickPin, 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
  
   interval1 = (1000L/tempo)*60/2; //algorithm to convert tempo into BPM
   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:
    ledState = !ledState;
     // delay(swingVal);
    // set the LED with the ledState of the variable:
    digitalWrite(ledPin, ledState);
    digitalWrite(tickPin, 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:
    ledState = !ledState;
     // delay(swingVal);
    // set the LED with the ledState of the variable:
    digitalWrite(ledPin, ledState);
    digitalWrite(tickPin, ledState);
  }
}

I think you want to produce something like this;

Tick
delay of interval1
Tock
delay of swingval
Tick
delay of interval1
and so on...

try this:

const int ledPin =  13; // the number of the LED pin
const int tickPin =  6; 
const int analogInPin = A0; // read pot for tempo value
const int analogInPin2 = A1; // read pot for swing value

int ledState = LOW;           
unsigned long previousMillis = 0;        
unsigned long interval1 = 1000UL;           // interval at which to blink (milliseconds)
unsigned long interval2 = 1000UL;
int tempo;
int sensorValue = 0;
int swingValue = 0;
int swingVal = 0;

void setup() {

  Serial.begin(9600);
  pinMode(ledPin, OUTPUT);
  pinMode(tickPin, 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

  interval1 = (1000L/tempo)*60/2; //algorithm to convert tempo into BPM
  interval2 = interval1 + swingVal;

  unsigned long currentMillis = millis();
  if (currentMillis - previousMillis > interval1) //Tick
  {
    ledState = !ledState;
    digitalWrite(ledPin, ledState);
    digitalWrite(tickPin, ledState);
  }
  else if (currentMillis - previousMillis > interval2) //Tock
  { 
    ledState = !ledState;
    digitalWrite(ledPin, ledState);
    digitalWrite(tickPin, ledState);
  }
  else
  {
    previousMillis = currentMillis;  
  } 
}

note my use of unsigned long variable type for the timer variables...

Thanks so much for helping out, that seems to make a lot of sense, but i'm not sure my board is liking it, doesn't seem to flash the LED or move the clock along, not sure, seems it's frozen!

I did notice

 interval1 = (1000L/tempo)*60/2; //algorithm to convert tempo into BPM

but in the start it says

unsigned long interval1 = 1000UL;

Do you think this could be contributing to it's lack of pulsation? Have tried a few different things, seems to compile with no errors but not getting the expected functionality, this is kinda scary trying to debgug!

40 Beats per minute = 1500milliseconds per beat, yes?

210 Bests per minute = 286 milliseconds per beat , right?

so try this instead:

  sensorValue = analogRead(analogInPin);
  swingValue = analogRead(analogInPin2);
  
  swingVal = map(swingValue, 0, 1023, 250, 0); // you have to adjust this...
  interval1 = map(sensorValue, 0, 1023, 1500, 286);
  interval2 = interval1 + swingVal;
const int ledPin =  13; // the number of the LED pin
const int tickPin =  6; 
const int analogInPin = A0; // read pot for tempo value
const int analogInPin2 = A1; // read pot for swing value

int ledState = LOW;           
unsigned long previousMillis = 0;        
unsigned long interval1 = 1000UL;           // interval at which to blink (milliseconds)
unsigned long interval2 = 1000UL;
int tempo;
int sensorValue = 0;
int swingValue = 0;
int swingVal = 0;

void setup() {

  Serial.begin(9600);
  pinMode(ledPin, OUTPUT);
  pinMode(tickPin, OUTPUT);  
}

void loop()
{
  sensorValue = analogRead(analogInPin);
  swingValue = analogRead(analogInPin2);
  
  swingVal = map(swingValue, 0, 1023, 250, 0); // you have to adjust this...
  interval1 = map(sensorValue, 0, 1023, 1500, 286);
  interval2 = interval1 + swingVal;
  
  unsigned long currentMillis = millis();
  if (currentMillis - previousMillis > interval1) //Tick
  {
    ledState = !ledState;
    digitalWrite(ledPin, ledState);
    digitalWrite(tickPin, ledState);
  }
  else if (currentMillis - previousMillis > interval2) //Tock
  { 
    ledState = !ledState;
    digitalWrite(ledPin, ledState);
    digitalWrite(tickPin, ledState);
  }
  else
  {
    previousMillis = currentMillis;  
  } 
}

Hey man yeah it's not working at all on my board not flashing the LED 13 at all, and put in some Serial.println's and nothing is showing up on the monitor at all.

I'm not sure if it's just my board, it's very old, Duemilanova could this have an effect? maybe something in the code isn't allowed on these old boards.

const int ledPin =  13; // the number of the LED pin
const int tickPin =  6; 
const int analogInPin = A0; // read pot for tempo value
const int analogInPin2 = A1; // read pot for swing value

int ledState = LOW;           
unsigned long previousMillis = 0;        
unsigned long interval1;           // interval at which to blink (milliseconds)
unsigned long interval2;
int tempo;
int sensorValue = 0;
int swingValue = 0;
int swingVal = 0;

void setup() {

  Serial.begin(9600);
  pinMode(ledPin, OUTPUT);
  pinMode(tickPin, OUTPUT);  
}

void loop()
{
  sensorValue = analogRead(analogInPin);
  swingValue = analogRead(analogInPin2);
  
 // swingVal = map(swingValue, 0, 1023, 10, 0); // you have to adjust this...
  interval1 = map(sensorValue, 0, 1023, 1500, 286);
  interval2 = interval1; //+ swingVal;
  
  unsigned long currentMillis = millis();
  if (currentMillis - previousMillis > interval1) //Tick
  {
    ledState = !ledState;
    digitalWrite(ledPin, ledState);
    Serial.println(interval1);
   // digitalWrite(tickPin, ledState);
  }
  else if (currentMillis - previousMillis > interval2) //Tock
  { 
    ledState = !ledState;
    digitalWrite(ledPin, ledState);
    Serial.println(ledState);
     Serial.println(interval2);
   // digitalWrite(tickPin, ledState);
  }
  else
  {
    previousMillis = currentMillis;  
  } 
}

Do you get the LED on pin 13 flashing at all? Nothing's even printing I'm really not sure why!

whoops!

I made a correction "<" instead of ">"

EDIT: maybe you need to define what you need it to do, step by step...

const int ledPin =  13; // the number of the LED pin
const int tickPin =  6; 
const int analogInPin = A0; // read pot for tempo value
const int analogInPin2 = A1; // read pot for swing value

int ledState;           
unsigned long previousMillis;        
unsigned long interval1;           // interval at which to blink (milliseconds)
unsigned long interval2;
int tempo;
int sensorValue = 0;
int swingValue = 0;
int swingVal = 0;

void setup() {

  Serial.begin(9600);
  pinMode(ledPin, OUTPUT);
  pinMode(tickPin, OUTPUT);  
}

void loop()
{
  sensorValue = analogRead(analogInPin);
  swingValue = analogRead(analogInPin2);
  
  swingVal = map(swingValue, 0, 1023, 0, 500); // you have to adjust this...
  interval1 = map(sensorValue, 0, 1023, 286, 1500);
  interval2 = interval1 + swingVal;
  
  unsigned long currentMillis = millis();
  if (currentMillis - previousMillis < interval1) //Tick
  {
    ledState = HIGH;
    digitalWrite(ledPin, ledState);
    digitalWrite(tickPin, ledState);
  }
  else if (currentMillis - previousMillis < interval2) //Tock
  { 
    ledState = LOW;
    digitalWrite(ledPin, ledState);
    digitalWrite(tickPin, ledState);
  }
  else
  {
    previousMillis = currentMillis;  
  } 
}

Hehe! Thanks so much for helping out, I think I need to test for the values of swing, as it's not gonna be the same value always, when the tempo changes it needs to change proportionally if that makes any sense. At the moment it's interval value + fixed value from pot. Swing value needs to be tempo relative I think, I'm actually not even sure this is the write way to do swing in the first place, it's proper hacky!

I'll try and work out the algorithm for it in max/msp tomorrow. I think I can make a neater way to test for the values in there as it's more dynamic.

So I just sketched out the algorithm in Max and found the error in my thinking. I think I've solved it in theory.

The algorithm is:

BPM/60 = BPS

1000/BPS = Interval Length in ms.

Interval 1 and Interval2 need to add together to always be equal, so the algorithm needs to be:

Interval1 + Offset, Interval2 - Offset.

Offset is mapped like 0-1023, 0-Interval Length/2.

So even though the Swingpot value remains in 0-1023, what it is mapped to is relative to the tempo. And also the length of bar remains the same this way.

Works in Max, just gonna see how hard it is to do on the Arduino!

Damn I'm think I'm so close, what am I doing wrong now?

const int ledPin =  13; // the number of the LED pin
const int tickPin =  6; 
const int analogInPin = A0; // read pot for tempo value
const int analogInPin2 = A1; // read pot for swing value

int ledState;           
unsigned long previousMillis;        
unsigned long interval;           // interval at which to blink (milliseconds)
unsigned long interval1;           // interval1 = interval + Offset
unsigned long interval2;           // interval2 = interval - Offset
int bpm = 120;
int bpmPot = 0;
int swingPot = 0;
int offset = 0;

void setup() {

  Serial.begin(9600);
  pinMode(ledPin, OUTPUT);
  pinMode(tickPin, OUTPUT);  
}

void loop()
{
  bpmPot = analogRead(analogInPin);
  swingPot = analogRead(analogInPin2);
  bpm = map(bpmPot, 0, 1023, 20, 200); // 1023 to bpm range.
  
  interval = 1000/(bpm/60); //interval in ms
  
  offset = map(swingPot, 0, 1023, 0, interval/2); // you have to adjust this...
  interval1 = interval + offset;
  interval2 = interval - offset;
  
  unsigned long currentMillis = millis();
  if (currentMillis - previousMillis < interval1) //Tick
  {
    ledState = HIGH;
    digitalWrite(ledPin, ledState);
    digitalWrite(tickPin, ledState);
  }
  else if (currentMillis - previousMillis < interval2) //Tock
  { 
    ledState = LOW;
    digitalWrite(ledPin, ledState);
    digitalWrite(tickPin, ledState);
  }
  else
  {
    previousMillis = currentMillis;  
  } 
}

This is the logic I thought it needed to work, in particular this:

  bpmPot = analogRead(analogInPin);
  swingPot = analogRead(analogInPin2);
  bpm = map(bpmPot, 0, 1023, 20, 200); // 1023 to bpm range.
  
  interval = 1000/(bpm/60); //interval in ms
  
  offset = map(swingPot, 0, 1023, 0, interval/2); // max limit of swing, tempo/interval relative
  interval1 = interval + offset;
  interval2 = interval - offset;

Does anyone have any ideas? It uploads and compiles fine, just not acting the way I'd hoped!

Damn I still haven't managed to get it working, the object [map] doesn't seem to like it when I use a variable to define it's max output value.

Or I am I getting something mixed up in the order of execution?

If anyone could point out the flaws I'd greatly appreciate it.

const int ledPin =  13; // the number of the LED pin
const int tickPin =  7; 
const int analogInPin = A0; // read pot for tempo value
const int analogInPin2 = A1; // read pot for swing value

int ledState;           
unsigned long previousMillis;        
unsigned long interval;           // interval at which to blink (milliseconds)
unsigned long interval1;           // interval1 = interval + Offset
unsigned long interval2;           // interval2 = interval - Offset
unsigned long offset;
unsigned long maxdelta;
int bpm = 0;
int bpmPot = 0;
int swingPot = 0;

void setup() {

  Serial.begin(9600);
  pinMode(ledPin, OUTPUT);
  pinMode(tickPin, OUTPUT);  
}

void loop()
{
  bpmPot = analogRead(analogInPin);
  swingPot = analogRead(analogInPin2);
  
 // Serial.print("\t SwingPot = ");
  //Serial.println(swingPot);
  bpm = map(bpmPot, 0, 1023, 20, 200); // 1023 to bpm range.
  
  offset = swingPot/4;
  
  Serial.print("\t BPM = ");
  Serial.println(bpm);
  
  interval = (60/bpm) * 1000; //interval in ms
  
 // maxdelta = (interval/2);
 // offset = map(swingPot, 0, 1023, 0, maxdelta); // cannot be greater than half length of interval.
 // map object doesn't like maxdelta being used
  //Serial.print("\t offset = ");
  //Serial.println(offset);
  
  interval1 = interval + offset; // Add offset value to first interval
  interval2 = interval - offset; // Subtract offset to make same length of bar.
  
  Serial.print("\t int1 = ");
  Serial.println(interval1);
  //Serial.print("\t int2 = ");
 // Serial.println(interval2);
  
  unsigned long currentMillis = millis();
  if (currentMillis - previousMillis < interval1) //Tick
  {
    ledState = HIGH;
    digitalWrite(ledPin, ledState);
    digitalWrite(tickPin, ledState);
  }
  else if (currentMillis - previousMillis < interval2) //Tock
  { 
    ledState = LOW;
    digitalWrite(ledPin, ledState);
    digitalWrite(tickPin, ledState);
  }
  else
  {
    previousMillis = currentMillis;  
  } 
}

The idea is making a swung rhythmic pulse, meaning instead of equal length beats, every other beat is slightly staggered. See the attached screen shot, this is what I'm trying to recreate with two pots, one for BPM and one for Swing/offset amount.

ok,

for my own edification... I am not a musician

let's say that a beat is represented on a 'visual metronome' as a led illuminated for 1/8th of the beat (an eighth note at the top of the beat)

so the metronome would look like this in eighths:

1000000010000000100000001000000010000000100000001000.....

with the time from the start of each beat being interval1 in your program. so if the beat was 60BPM, the duration of the LED illumination will be 1/8of of a second or 125ms.

So far are we on the same page?

then, for the notes inégales you want to increase the duration of every other illumination by the value of the swing. so as in the example, if we swing the note by 125ms (combined with the 1/8th note, now equal to a 1/4 note in the primary beat) your swung note is now 250ms in length.

is that right?

so the regular visual metronome would look like this

0-125ms LED on
126-1000ms LED off
0-125ms LED on
126-1000ms LEDoff
etc...

the beat in a swung metronome would look like this

0-125ms LED on
126-1000ms LED off
0-250ms LED on
251-1000ms LEDoff
0-125ms LED on
126-1000ms LED off
0-250ms LED on
251-1000ms LEDoff
etc...

or do we increase the entire beat by 8X the swing like this:

0-125ms LED on
126-1000ms LED off
0-250ms LED on
251-2000ms LEDoff
0-125ms LED on
126-1000ms LED off
0-250ms LED on
251-2000ms LEDoff
etc...

try to explain like this for us untalented types...

haha untalented I wouldn't say that at all, anyone that has a knack for uProcessor stuff certainly has talent!

So I think it does get confusing with LED having to be turned off as well, wasn't taking that into consideration only cared about the clock tick, and think it only moves forward when it's HIGH, and doesn't care for the duration between Hi/Lo.

So the duration of the pulse that gets sent on Digital pin6/7 is arbitrary, doesn't need to be tempo related I don't think. What's most important is the time between first HIGH and 2nd HIGH.

Maybe this is a better way to visualise:

B000 || B000 // Equal Length of beat // Offset = 0 // 3/3
B0000 || B00 // Offset adds one to first beat and subtracts one from second beat // Offset = 1 // 4/2
B00000 || B0 // 2nd iteration, offset adds one to first and subtracts one from second // Offset = 2 // 5/1

B = HIGH

HIGH <--Interval 1--> HIGH <--Interavl2--> HIGH <--Interval 1--> HIGH <--Interavl2--> HIGH etc

When the low is switched off is arbitrary I think. Could be fixed.

So you have a BPM pot that turns in Beats per Second and then Duration in ms or Delta Time, Duration in between pulses like on a metronome that goes tick, but instead of the tick and tock being equal, the tick is slightly longer than the tock.

so this will do what you want on led13, I hope.

beat interval1 beat interval2 beat interval1 beat interval2 ...

try it and let me know what you think...

 const int ledPin =  13; // the number of the LED pin
const int tickPin =  6; 
const int analogInPin = A0; // read pot for tempo value
const int analogInPin2 = A1; // read pot for swing value

int ledState;           
unsigned long lastBeat;        
unsigned long interval1;           // interval at which to blink (milliseconds)
unsigned long interval2;
int tempo;
int beatValue = 0;
int swingValue = 0;
int swingVal = 0;
int state;

void setup() {

  Serial.begin(9600);
  pinMode(ledPin, OUTPUT);
  pinMode(tickPin, OUTPUT);  
}

void loop()
{
  beatValue = analogRead(analogInPin);  // I put values here because I dont't have the pots here
  swingValue = analogRead(analogInPin2);
  
  swingVal = map(swingValue, 0, 1023, 0, 500); // adjusts zero to one half second swing
  interval1 = map(beatValue, 0, 1023, 1500, 286);// adjusts Beats per Minute
  interval2 = interval1 + swingVal;
  if (state == 0) beat(interval1);
  if (state == 1) beat(interval2);
}
  
void beat(unsigned long duration)
{

  if (millis() - lastBeat <= 250UL)
  {
    ledState = HIGH;
    digitalWrite(ledPin, HIGH);
    digitalWrite(tickPin, ledState);
  }
  else if (millis() - lastBeat <= duration)
  { 
    ledState = LOW;
    digitalWrite(ledPin, LOW);
    digitalWrite(tickPin, ledState);
  }
  else
  {
    lastBeat = millis(); 
    state = 1 - state; 
  } 
}

Right so I've been messing around with this in my spare time and think I might have stumbled on the error of my ways, in the code you posted it seems like it's going, 2 long, 2 short, instead of one long, one short.

I've been testing the concept and made it with delay in it's most simple form:

void setup() {
  // initialize digital pin 13 as an output.
  Serial.begin(9600);
  pinMode(5, OUTPUT); // Tick pin for drum machine
  pinMode(13, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  analogWrite(5, 255);  //
  digitalWrite(13, HIGH);  
  delay(204);              
  analogWrite(5, 0);    
  digitalWrite(13, LOW);   // turn the LED on (HIGH is the voltage level)
  delay(204);              // wait for a second
  analogWrite(5, 255);   // turn the LED on (HIGH is the voltage level)
  digitalWrite(13, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(128);              // wait for a second
  analogWrite(5, 0);    // turn the LED off by making the voltage LOW
  digitalWrite(13, LOW);   // turn the LED on (HIGH is the voltage level)
  delay(128);              // wait for a second
  
  
}

So at 90 bpm the intervals when they are even are actually 166.7 HIGH, 166.7 LOW for the first interval and 166.7 HIGH, 166.7 LOW. For the swing it's around 204, 128, sounds ok.

I've seen a guy do it with a physical delay pedal setup and looks ridiculously long winded: Shuffle / Swing on the Korg Volca Series - YouTube

Really wanna simplify that process!

One thing's really bugging me, I can't seem to get working, can you use a value that's a variable in map? i.e.:

swingVal = map(swingValue, 0, 1023, 0, variable);

So the actual function is for some reason BPM/15 =x , 1000/x = interval, interval/2 = maximum swing value. So i've broken it into equal parts HIGH and LOW for the LED interval value1, and equal parts for interval2 HIGH and LOW, or analog write 255 and 0. I can get it to work in the rudimentary form, but need to expand to work with reading the two pots for tempo and swing. Anyone have any idea?