Cycling through variables with buttons?

Hi guys! I have a pretty basic sketch running a stepper motor with the SparkFun Easy Driver, and then triggering something else.

The project is basically a camera control rig, and I need the ability to change settings.

I’ve got variables written for all the things I need to change for different settings, but now I need to be able to cycle through the variables (and apply them to the right places) with separate buttons.

I need one button to cycle through the 4 different settings I want to change, and when “highlighting” each a second button to cycle through each option, and then one button to start the loop.

Eg.
Press button 1 = StepDistance is selected
Press button 1 = Exposure is selected
Press button 2 = Exposure1 is selected and applied to delay(Exposure); //Exposure time
Press button 2 = Exposure2 is selected and applied to delay(Exposure); //Exposure time
Press button 2 = Exposure3 is selected and applied to delay(Exposure); //Exposure time
Press button 3 = Loop starts
Press button 3 = loop starts
and so on…

I have NO idea how to go about this, and I’m just kind of stuck. I think if I can have help with this part I’ll be able to move onto printing to an LCD myself, but as I said I just feel stuck at this point.

Any and all help would be massively appreciated! Thank you!! :slight_smile:
Willing to pay if I have to for help, I really need to get this done within the next couple of days.

Here is the code!

//Slider Code with EasyDriver//


//Pins assigned//
int dirpin = 2;
int steppin = 3;
int TimerPin = 13;

//Camera Slider Speed Variables//
int CameraSpeed1 = 800; //Max speed - Live video//
int CameraSpeed2 = 1200; 
int CameraSpeed3 = 4000;
int CameraSpeed4 = 10000;
int CameraSpeed5 = 50000;
int CameraSpeed6 = 80000; //Slowest Speed//


//Camera Slider Distance Per Step// //25 steps = 1mm// //576mm track// 14400 steps per track//
int StepDistance1 = 10; //Ultra slow to move accross track//
int StepDistance2 = 20;
int StepDistance3 = 25; //1mm//
int StepDistance4 = 35;
int StepDistance5 = 45;
int StepDistance6 = 55;
int StepDistance7 = 85;
int StepDistance8 = 100;
int StepDistance9 = 12000; //half the track
int StepDistance10 = 22500; //full length of track//

//Exposure Time//
int Exposure = 500;
int Exposure1 = 1000;
int Exposure2 = 2000;
int Exposure3 = 3000;
int Exposure4 = 4000;
int Exposure5 = 5000;
int Exposure6 = 6000;
int Exposure7 = 7000;
int Exposure8 = 8000;
int Exposure9 = 9000;
int Exposure10 = 10000;
int Exposure11 = 11000;
int Exposure12 = 12000;
int Exposure13 = 13000;
int Exposure14 = 14000;
int Exposure15 = 15000;
int Exposure16 = 16000;
int Exposure17 = 17000;
int Exposure18 = 18000;
int Exposure19 = 19000;
int Exposure20 = 20000;
int Exposure21 = 21000;
int Exposure22 = 22000;
int Exposure23 = 23000;
int Exposure24 = 24000;
int Exposure25 = 25000;
int Exposure26 = 26000;
int Exposure27 = 27000;
int Exposure28 = 28000;
int Exposure29 = 29000;
int Exposure30 = 30000;
int Exposure35 = 35000;
int Exposure40 = 40000;
int Exposure50 = 50000;
int Exposure60 = 60000;

//Slider Direction//
int Left = LOW;
int Right = HIGH;


void setup() 
{
pinMode(dirpin, OUTPUT);
pinMode(steppin, OUTPUT);
pinMode(TimerPin, OUTPUT);
}
void loop()
{

  int i;

  digitalWrite(dirpin, Left);     // Set the direction. LOW = to motor, HIGH = away
  delay(0);


  for (i = 0; i<StepDistance3; i++)         //  DISTANCE PER LOOP 22500 is the length of the track
  {
    digitalWrite(steppin, LOW);  // 
    digitalWrite(steppin, HIGH); //
    delayMicroseconds(CameraSpeed1);     //Speed - max of 800
  }

 
   delay(800);    //pause between stopping and shooting
   digitalWrite(TimerPin, HIGH);
   delay(Exposure);  //Exposure time
   digitalWrite(TimerPin, LOW);
   delay(800);    //pause before moving again

        

}

Thanks again,
Jesse.

If you just want to hire someone, you can ask a moderator to move it to the "gigs and collaborations" forum.

I have NO idea how to go about this, and I'm just kind of stuck.

Each time you press a switch (buttons are for shirts), you want to change state. Look at the state change detection example, and google state machine.

The hardest part about what you want to do is wiring the switches correctly (one leg to ground, one leg to a digital pin, and set the mode of the pin to INPUT_PULLUP) and providing the user with feedback, so that they know what state is selected with each press of a switch.

I guess you should have an array for each camera setting:

eg for StepDistance

const int StepDistanceElements = 10 ;
unsigned long StepDistance[ StepDistanceElements ]
int StepDistanceIndex = 0 ;

StepDistance[0] = 10; //Ultra slow to move accross track//
StepDistance[1] = 20;
StepDistance[2] = 25; //1mm//
. . .
StepDistance[9] = 22500; //full length of track//
. . .


void loop() {
   . . .
   . . .

   if ( buttonPressDetected() ) {
      // cycle through StepDistance
      Serial.print ( StepDistance[StepDistanceIndex] ) ;
      StepDistanceIndex ++ ;
      if ( StepDistanceIndex == StepDistanceElements ) {
            StepDistanceIndex = 0 ;
      }
   }
   . . .
   . . .
}

Repeat this for each setting and also for the "Main Menu"

6v6gt:
I guess you should have an array for each camera setting:

eg for StepDistance

int StepDistanceElements = 10 ;

unsigned long StepDistance[ StepDistanceElements ]
inf StepDistanceIndex = 0 ;

StepDistance[0] = 10; //Ultra slow to move accross track//
StepDistance[1] = 20;
StepDistance[2] = 25; //1mm//
. . .
StepDistance[9] = 22500; //full length of track//

if ( buttonPressDetected() ) {
  // cycle through StepDistance
  Serial.print ( StepDistance[StepDistanceIndex] ) ;
  StepDistanceIndex ++ ;
  if ( StepDistanceIndex == StepDistanceElements ) {
        StepDistanceIndex = 0 ;
  }
}




Repeat this for each setting and also for the "Main Menu"

Thank you for your help! :slight_smile: