using external input to write to program

I've searched the forum but possibly am not using the right terms. Here's the situation.....I have "int runSize = " in my program and the sketch is written so that the program cycles the number of times I set runSize equal to then stops. It works fine but I currently have to reupload a new sketch with the number I want in order to change it. Once I'm done testing the controller will not have a computer hooked up and even if it did I would not want operators editing the program. What options, if any, do I have for some sort of external input of the number into the sketch? Thanks.

You could use two buttons. One to increase the number, and the other that would decrease that number.

I used an IR remote to do something similar.

Just to add a little more info I'd be looking at inputting numbers in the 1,000 to 6,000 range. That would be a lot of button pushes! lol Intrigued by the ir remote. Was wondering about some sort of keypad on my control console that could interface with the program.

I assigned a button to step 50 another to step 10 and one to step one.

You can define a duration of the button press. Hold down longer than 3 seconds, add by 100, longer than 1 second, add 10, less than 1 second add 1. Got the idea?

You are committing the oh-so-frequent mistake called the "XY problem".

You need to first explain what it is that you need to control, not how to muck about in a program, which is the easy bit.

What is the purpose of the operation that you need up to 6000 of? Once we know that, we will know how you really need to define it.

In addition to what @Paul_B said

  • how often do you need to change the variable?
  • must the new value be remembered even if the Arduino is switched off?

Would you be interested in the option to update the number from a phone or a PC using Bluetooth - that is not difficult.

...R

hold down the button, if reached 10,20,30,.... add 10 if reached 100,200, etc add 100 etc. however you will need a display. another way is a potmeter. or an encoder, or .....

My apologies for possibly not explaining enough. I was trying to keep the post on point. The concept of the project is described here:

http://forum.arduino.cc/index.php?topic=339460.0

PaulB and Robin you both helped with my earliest issues. Now I have a functioning program and prototype and when it is turned on it will continuously cycle the air cylinders in the appropriate sequence and at the appropriate times. I have also added a cycle count to the code which counts to a serial monitor. I intend to use an LCD screen with serial interface to display the count. Once I figured out how to make it count cycles I added code where I can set a limit to the number of cycles it runs before shutting down. For the most part this would not be used because we would want the welder to produce parts all day as long as someone is there to load the hopper with raw parts. There may however be some instances where we only want to run a certain number of parts, say arbitrarily 2,500. I can just have an operator watch the counter and stop when we reach 2,500 but since I already have code that will count and stop at a set point I thought it would be nice (yes, I'm into the "bells & whistles" phase) to be able to input that number via buttons, switches, a keypad, etc on the control console. So I'm looking for a simple way to input a number into the "int runSize = " line of my sketch, preferably using something that is part of the control console rather than an external device such as a computer or phone.

If your control console displays how many are left, then you could use any of the mentioned inputs to adjust that number. Does "how many are left" show on your control console display ?

Jack,
Not currently. As a matter of fact I don’t actually have the display yet, I’m waiting for it to be shipped and then will have to learn how to integrate it. What I currently have uses a cycleCount and runSize with the following relative codes:

if (CycleCount < runSize) at the top of the loop and

CycleCount = CycleCount + 1; at the bottom

So I can upload a code with whatever I want here:

int runSize = 100;//number of cycles to run before stopping

and it will run to that number and stop.

I’m currently monitoring that using the Arduino IDE serial monitor and plan on using the LCD with serial interface to do that in the finished project. So right now it counts up instead of down.

"So right now it counts up instead of down."

maybe switching that to count down would be worth considering. Uses only one variable rather than two, and allows easier operator control. What do you think?

My only hesitance in counting down would be this......in a count up scenario when the run finishes the number of completed parts in the bin is what is shown on the display, in a count down scenario the display reads zero and someone has to know what the run size was set at to know how many parts are in the bin. That's not a deal breaker but when you are dealing with unskilled workers you'd be amazed the stuff you take for granted that winds up biting you in the ass. lol I have a 4 line display on the way so I could probably use one line to show the overall size of the run and a second line to show the countdown to zero as the run progresses. But for the purpose of my Arduino education I don't really see the difference.....either way I need to figure out how to plug a number into the code from my console, correct?

"either way I need to figure out how to plug a number into the code from my console, correct?"

Yes!

For minimal hardware, it should work sorta like setting a electric clock. One button moves the number up (either slowly, or fast), the other button moves the number down (either slowly, or facs).

Do you have a different entry system in mind?

Your display can display several things, such as: How many have been created: 200 How many left to create: 600 total to be created for this run: 800

So, you could change "how many left to create", and the total run will adjust.

That would work. For what I need I could probably get away with each button push of the "up" button adding 250 to the total and each push of the "down" button subtracting 50. Then by a combination of up and down I could reasonably quickly get to any multiple of 50 which would be close enough for our purposes.

"Do you have a different entry system in mind?"

I was actually thinking about something like this where you could just enter the amount but I have no idea how to get those keypresses to register in the variable for the run size.

http://www.adafruit.com/products/419?gclid=Cj0KEQjwmNuuBRDTu5rDjr2kxJsBEiQAWlm6UrTV60bvYdDuXNGMqjcoA_CxlY6KvO6hIv2rAQyiwG8aAsnY8P8HAQ

I am not familiar with the workings for that keypad.

Your idea of 250 up, and 50 down, sounds like a sound option. The results being displayed on the readout. Yes, I like that idea.

So if I went that route would this be the basic process (logic, not actual code)?

initialize runSize at 0

if “up” button is pressed, runSize = runsize + 250

if “down” button is pressed, runSize = runSize - 50

serial print runSize to the display

And I believe this all needs to run inside the loop, correct?

Other than that I just change my current code to count down, runSize = runSize - 1

and if runSize > 0, run the loop

Is that basically it?

I realize there is more if I want to have the “set” runSize continue to be displayed on the screen along with the countdown progress but I’m pretty sure I can work that out.

That looks like what I think you want/need.

If you are displaying both, total for run, and qty left, the operator can determine which ever one is appropriate (probably total for run).

If you have further questions, we are all ears.

Thank you. My next step will be to get the current version of the sketch working with the display (when it arrives) then I will move on to trying to work this out. As Arnold once said "I'll be back!" ;-)