Need help with an 8 step sequencer

Hello I have been trying to wrap my head around this issue for a couple of days now. I have an 8 step sequencer taking analog reads from a slide pot. I would like to only update the array if the slider is moved and on that specific step. If there is no slider movement i want it to continue looping the same 8 step sequence. Right now when the record button is held it holds the sequence but i cant figure how to approach what i am trying to do which is.

  1. if the slider is moved update current step with new voltage reading.
    2)do not change any other steps if movement stops

in essencei want the slider movement to tell the sequencer to record new data to current step
if slider moves through all steps , then all steps will be updated until movement stops

I can make it continuously update the array but cant make it stop when there isnt any movement.
Any help is greatly appreciated. please see below

#include <Bounce.h>



//******Sequencer Setup************* WORKING!!!

int stepcount = 4;        //was CONST INT but changed.
int currentstep = 0;
float BPM = 70.0;
float MINBPM = 40.0;
float MAXBPM = 300.0;
float interval = 0;
bool playstatehold = 0; //holds value of playstate wither on or off
int bpmpotval = 0;


// setup for reading the 8 pots

  int PotVal1 = 0;
  int PotVal2 = 0;
  int PotVal3 = 0;
  int PotVal4 = 0;
  int PotVal5 = 0;
  int PotVal6 = 0;
  int PotVal7 = 0;
  int PotVal8 = 0;

// voltage reading holders
  float Lastvoltage1 = 0;
  float voltage1 = 0;
  float voltage2 = 0;
  float voltage3 = 0;
  float voltage4 = 0;
  float voltage5 = 0;
  float voltage6 = 0;
  float voltage7 = 0;
  float voltage8 = 0;

// for blinking led
long ledmillis = 0;
int ledstate = HIGH;

// used to track how long ago the last event fired
unsigned long laststeptime = 0;



// Sequencer arrays

float Seq1[16];
float Seq1Hold[16];

float Seq2[16];
float Seq3[16];
float Seq4[16];
float Seq5[16];
float Seq6[16];
float Seq7[16];
float Seq8[16];


//***PINS**   WHAT IS ASSIGNED TO WHICH PIN
int bpmled = 13;
int stoppin = 2;
int playpin = 3;
int clearpin = 4;
int rec = 5;

bool sc1 = 0;

void setup() {

  Serial.begin(9600);


//******************SET PIN MODES*******************
  pinMode(bpmled, OUTPUT);
  pinMode(stoppin, INPUT_PULLUP);
  pinMode(playpin, INPUT_PULLUP);
  pinMode(rec, INPUT_PULLUP);

  

}


void loop() {

  sliderchange();
  PotRead();
  playstate();
  mainseq();
//  bpmpotread();
 


  
}


// calculates the bpm for the sequence

void mainseq() {
  

  interval = (60000 / BPM);
 

}


// controls play state either playing or stopped

void playstate(){

  
  if(digitalRead(playpin) == LOW){
    playstatehold = 1;
    
  }
  if(digitalRead(stoppin) == LOW){
    playstatehold = 0;
    
  }

  if(playstatehold == 1){

    stepfoward();
    ledblink();
  }
  else{
    
    ledstate = LOW;
  }
  
}

// controls moving the sequence foward and holding last step time

void stepfoward() {

  if (millis() > (laststeptime + interval)) {

    currentstep++;
    
    if (currentstep > stepcount - 1) {
      currentstep = 0;
      
    }
    
    laststeptime = millis();

     

    
      
   if(digitalRead(rec) == LOW){
    Seq1[currentstep] = voltage1;

    
    }



        
//*****************************DEBUG FOR SETP FOWARD******************************************
   Serial.print(   BPM);
   Serial.print("      ");
   Serial.print(Seq1[currentstep]);
   Serial.print("      ");
   Serial.print(Seq1Hold[currentstep]);
   Serial.print("      ");
   Serial.print(voltage1);
   Serial.print("      ");
   Serial.print(sc1);
   Serial.print("      ");
   Serial.println(currentstep);

      
  }


        

     
      
     

   
 
}


// Blink LED at speed of BPM

void ledblink() {

  unsigned long currentMillis = millis();

  if (currentMillis - ledmillis > interval / 2 ) {
    // save the last time you blinked the LED
    ledmillis = currentMillis ;

    // if the LED is off turn it on and vice-versa:
    if (ledstate == LOW){
      ledstate = HIGH;
      
    }
      
    else{
      ledstate = LOW;
      
    }
    // set the LED with the ledState of the variable:
    digitalWrite(bpmled, ledstate);
    

  }
  
}


// READS THE POT FOR BPM

void bpmpotread(){

  bpmpotval = analogRead(A5);

  BPM = map(bpmpotval, 0, 1024, MINBPM, MAXBPM);
  
  
}

// Analog Read All 8 pots
void PotRead(){

   // read the input on analog pin 0-7:
  PotVal1 = analogRead(A0);
  PotVal2 = analogRead(A1);
  PotVal3 = analogRead(A2);
  PotVal4 = analogRead(A3);
  PotVal5 = analogRead(A4);
  PotVal6 = analogRead(A5);
  PotVal7 = analogRead(A6);
  PotVal8 = analogRead(A7);
 
  // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
  voltage1 = PotVal1 * (5.0 / 1024.0);
  voltage2 = PotVal2 * (5.0 / 1024.0);
  voltage3 = PotVal3 * (5.0 / 1024.0);
  voltage4 = PotVal4 * (5.0 / 1024.0);
  voltage5 = PotVal5 * (5.0 / 1024.0);
  voltage6 = PotVal6 * (5.0 / 1024.0);
  voltage7 = PotVal7 * (5.0 / 1024.0);
  voltage8 = PotVal8 * (5.0 / 1024.0);

}

void sliderchange(){


  if (Seq1Hold[currentstep] == voltage1){
    sc1 = 0;
  }

  else{
    sc1 = 1;
  }

  
}

Your post was MOVED to its current location as it is more suitable.

What is happening using the current code?

Current code will record when record button is pressed. Inside of void stepfoward. I have tried some if statements but nothing i tried works. I can make it continuously update but cant understand how to make it only update when the slider is moved

Your words doesn't make it clear to understand what You've got and what You want to achieve. You use Your private terminology and it doesn't work.

Document the code in a flow chart.

Understood. will reply with flowchart shortly

And the full sketch please

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination

If you want to do something only when the value returned from an analogRead() changes then you need to have remembered what the last value read was. I can't see anywhere that you're attempting to do that.

OTOH the code contains 9 arrays and at least 8 pots so I have no idea which of those is "the array" and "the pot" that you are talking about.

Steve

goal:

8 step sequencer with 8 channels(lanes)
8 outputs to control eurorack gear with 0-5v CV
each channel is controlled by its own slider pot
when a slider is moved (ie. slider 1) it will update the voltage output for that channel(ch1) and step(1 to 8).
when the slider is not being moved no changes will be made to the sequence and it will loop until stop button is pressed.

Currently:

Only Variable label with 1 are currently used (ie. Seq1[] , PotVal1, voltage1, Lastvoltage1) all others can be ignored

1 channel

code runs 8 steps stored in a variable called "currentstep" at a specified BPM(beats per minute) using millis as a clock.

After step 8 it will loop back to step 1 continuously. creating a looping voltage sequence of 8 steps that is stored in Seq1 array. i use Seq1[currentstep] to keep the first step lined up with the first array entry "Seq1[0]"

Also here when button(record) is pressed the current value of "voltage1" is stored in the array at the current step position "Seq1[currentstep] "

void stepfoward() {

  if (millis() > (laststeptime + interval)) {

    currentstep++;
    
    if (currentstep > stepcount - 1) {
      currentstep = 0;
      
    }
    
    laststeptime = millis();

 
   if(digitalRead(rec) == LOW){
    Seq1[currentstep] = voltage1;

    
    }



        
//*****************************DEBUG FOR SETP FOWARD******************************************
   Serial.print(   BPM);
   Serial.print("      ");
   Serial.print(Seq1[currentstep]);
   Serial.print("      ");
   Serial.print(Seq1Hold[currentstep]);
   Serial.print("      ");
   Serial.print(voltage1);
   Serial.print("      ");
   Serial.print(sc1);
   Serial.print("      ");
   Serial.println(currentstep);

      
  }


        

     
      
     

   
 
}

100k Slider pot controls what voltage is read at A0 (0-5v)

analogRead is done on A0 at each step"currentstep", then converted to a voltage and stored in a variable called "voltage1"

  • only Variables with label 1 are being used currently. *
// Analog Read All 8 pots
void PotRead(){

   // read the input on analog pin 0-7:
  PotVal1 = analogRead(A0);
  PotVal2 = analogRead(A1);
  PotVal3 = analogRead(A2);
  PotVal4 = analogRead(A3);
  PotVal5 = analogRead(A4);
  PotVal6 = analogRead(A5);
  PotVal7 = analogRead(A6);
  PotVal8 = analogRead(A7);
 
  // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
  voltage1 = PotVal1 * (5.0 / 1024.0);
  voltage2 = PotVal2 * (5.0 / 1024.0);
  voltage3 = PotVal3 * (5.0 / 1024.0);
  voltage4 = PotVal4 * (5.0 / 1024.0);
  voltage5 = PotVal5 * (5.0 / 1024.0);
  voltage6 = PotVal6 * (5.0 / 1024.0);
  voltage7 = PotVal7 * (5.0 / 1024.0);
  voltage8 = PotVal8 * (5.0 / 1024.0);

}

I understand that i need to store the last voltage somehow and compare that to the current but im not sure how to approach it. I tried creating this below to first show that the slider value has changed but im super new to this and pretty sure its not how i should do it

void sliderchange(){


  if (Seq1Hold[currentstep] == voltage1){
    sc1 = 0;
  }

  else{
    sc1 = 1;
  }

  
}

i made some variables "Seq1Hold" this i was thinking would store the previous 8 steps and compare to current but that thinking didnt pan out.

i then made "Lastvoltage1" to try and store the previous voltage but im hitting a road block trying to figure out how to store this at each step without it changing to the current value.

I hope this explains it a bit more thank you for your time and help guys please let me know if i need to explain some areas better.