Adding keyboard input to change int

Pretty new at this so need some advice.

I have this sketch I have made and need some way to change the int numShootMoveLR=4; number before the sketch starts to run. I would like to do it from a keyboard (or other suggestion) but can NOT do it from computer because this will be a stand alone application later. I need a input range of 1-20.

Thanks for any suggestions.

THE_FINAL_W_LCD__compact_.ino (6.78 KB)

I’m using a phone to read the forum. My advice is to post the code with code tags instead of attaching it.

#include <LiquidCrystal.h>
#include <Stepper.h>

LiquidCrystal lcd(1,2,4,5,6,7); //initialize the liquid cystal library pins on 1,2,4,5,6,7

int stepsPerRevolution = 200; // number of steps per revolution
int cameraFirePin = 12; //fires camera shutter
int buttonPin = 13; //defines pin as start button
Stepper myStepperMOVINGLeft(stepsPerRevolution,8,9); // initialize the stepper library on pins 8 and 9
Stepper myStepperMOVINGRight(stepsPerRevolution,9,8); // initialize the stepper library on pins 9 and 8
Stepper myStepperMOVINGDown(stepsPerRevolution,10,11); // initialize the stepper library on pins 10 and 11
Stepper myStepperMOVINGUp(stepsPerRevolution,11,10); // initialize the stepper library on pins 11 and 10
int numShootMoveLR=4; //number of times to shoot and move to next position
int numShootMoveUp=1; //number of times to shoot and move to next row

void setup() {

lcd.begin (16,4); //defines lcd is 16 characters long in 4 rows

myStepperMOVINGLeft.setSpeed(2500);// set the speed at 2500 rpm:
myStepperMOVINGRight.setSpeed(2500);// set the speed at 2500 rpm:
myStepperMOVINGDown.setSpeed(2500);// set the speed at 2500 rpm:
myStepperMOVINGUp.setSpeed(2500);// set the speed at 2500 rpm:
pinMode(buttonPin,INPUT_PULLUP); // set the pin for button as INPUT

}

void loop(){

if (digitalRead(buttonPin) == LOW) { //starts everything

for (int j=1;j<=numShootMoveLR; j=j+1){

lcd.clear(); //clears the lcd
lcd.print(“TAKING PHOTO”); //alerts camera is shooting
digitalWrite(cameraFirePin, HIGH); //fires camera shutter through relay board
delay(3000);
digitalWrite(cameraFirePin, LOW); //de-powers relay board
delay(3000);
lcd.clear(); //clears the lcd
lcd.print(“MOVING TO NEXT”); //alerts camera is moving
myStepperMOVINGLeft.step(25000); // MOVINGs table to left
lcd.clear(); //clears the lcd
}

for (int j=1;j<=numShootMoveUp; j=j+1){

lcd.print(“MOVING TO NEXT”);//alerts camera is moving
myStepperMOVINGUp.step(25000); // moves camera up one row
lcd.clear(); //clears the lcd
lcd.print(“TAKING PHOTO”); //alerts camera is shooting
delay(3000);
digitalWrite(cameraFirePin, HIGH); //fires camera shutter through relay board
delay(3000);
digitalWrite(cameraFirePin, LOW); //de-powers relay board
delay(3000);
lcd.clear(); //clears the lcd
}

for (int j=1;j<=numShootMoveLR; j=j+1){

lcd.print(“MOVING TO NEXT”);//alerts camera is moving
myStepperMOVINGRight.step(25000); // moves camera to right
lcd.clear(); //clears the lcd
lcd.print(“TAKING PHOTO”); //alerts camera is shooting
delay(3000);
digitalWrite(cameraFirePin, HIGH); //fires camera shutter through relay board
delay(3000);
digitalWrite(cameraFirePin, LOW); //de-powers relay board
delay(3000);
lcd.clear(); //clears the lcd
}

for (int j=1;j<=numShootMoveUp; j=j+1){

lcd.print(“MOVING TO NEXT”);//alerts camera is moving
myStepperMOVINGUp.step(25000); // moves camera up one row
lcd.clear(); //clears the lcd
lcd.print(“TAKING PHOTO”); //alerts camera is shooting
delay(3000);
digitalWrite(cameraFirePin, HIGH); //fires camera shutter through relay board
delay(3000);
digitalWrite(cameraFirePin, LOW); //de-powers relay board
delay(3000);
lcd.clear(); //clears the lcd
}

for (int j=1;j<=numShootMoveLR; j=j+1){

lcd.print(“MOVING TO NEXT”);//alerts camera is moving
myStepperMOVINGLeft.step(25000); // moves camera to left
lcd.clear(); //clears the lcd
lcd.print(“TAKING PHOTO”); //alerts camera is shooting
delay(3000);
digitalWrite(cameraFirePin, HIGH); //fires camera shutter through relay board
delay(3000);
digitalWrite(cameraFirePin, LOW); //de-powers relay board
delay(3000);
lcd.clear(); //clears the lcd
}

for (int j=1;j<=numShootMoveUp; j=j+1){

lcd.print(“MOVING TO NEXT”);//alerts camera is moving
myStepperMOVINGUp.step(25000); //moves camera up one row
lcd.clear(); //clears the lcd
lcd.print(“TAKING PHOTO”); //alerts camera is shooting
delay(3000);
digitalWrite(cameraFirePin, HIGH); //fires camera shutter through relay board
delay(3000);
digitalWrite(cameraFirePin, LOW); //de-powers relay board
delay(3000);
lcd.clear(); //clears the lcd
}

for (int j=1;j<=numShootMoveLR; j=j+1){

lcd.print(“MOVING TO NEXT”);//alerts camera is moving
myStepperMOVINGRight.step(25000); // moves camera to right
lcd.clear(); //clears the lcd
lcd.print(“TAKING PHOTO”); //alerts camera is shooting
delay(3000);
digitalWrite(cameraFirePin, HIGH); //fires camera shutter through relay board
delay(3000);
digitalWrite(cameraFirePin, LOW); //de-powers relay board
delay(3000);
lcd.clear(); //clears the lcd
}

for (int j=1;j<=numShootMoveUp; j=j+1){

lcd.print(“MOVING TO NEXT”);//alerts camera is moving
myStepperMOVINGUp.step(25000); //move camera up one row
lcd.clear(); //clears the lcd
lcd.print(“TAKING PHOTO”); //alerts camera is shooting
delay(3000);
digitalWrite(cameraFirePin, HIGH); //fires camera shutter through relay board
delay(3000);
digitalWrite(cameraFirePin, LOW); //de-powers relay board
delay(3000);
lcd.clear(); //clears the lcd
}

for (int j=1;j<=numShootMoveLR; j=j+1){

lcd.print(“MOVING TO NEXT”);//alerts camera is moving
myStepperMOVINGLeft.step(25000); // moves camera to left
lcd.clear(); //clears the lcd
lcd.print(“TAKING PHOTO”); //alerts camera is shooting
delay(3000);
digitalWrite(cameraFirePin, HIGH); //fires camera shutter through relay board
delay(3000);
digitalWrite(cameraFirePin, LOW); //de-powers relay board
delay(3000);
lcd.clear(); //clears the lcd
}

lcd.print(“MOVING TO HOME”);//alerts camera is moving

myStepperMOVINGRight.step(25000); // move camera to right to home position
myStepperMOVINGRight.step(25000); // move camera to right to home position
myStepperMOVINGRight.step(25000); // move camera to right to home position
myStepperMOVINGRight.step(25000); // move camera to right to home position

myStepperMOVINGDown.step(25000); // move camera down to home position
myStepperMOVINGDown.step(25000); // move camera down to home position
myStepperMOVINGDown.step(25000); // move camera down to home position
myStepperMOVINGDown.step(25000); // move camera down to home position

lcd.clear(); //clears the lcd
lcd.print(“READY TO START”);

}
}

//end of steppermotorfunction

By no means an in depth analysis but, you could add another pushbutton which cycles through 4-20 and starts over at 1. Put this in a while loop which runs at the top of the program until the START pushbutton is pressed. Since you already have the LCD, prompts and feedback could be provided to the user.

You may be admonished to replace the delay()s with millis() delays.

That is a great idea. Thanks!

You may be admonished to replace the delay()s with millis() delays.<<<<

Could you explain why please?

When processing a delay(), no other code is executed. If your program needs to do something else while delay() is running - like checking a sensor or updating some output - it isn't going to happen until delay() is done. The way around this is to do several things at once.