Running Code Outside of Main Loop ( )

Hi

I'm fairly new to Arduino and coding but I'm loving it.

I have a relatively simple question, I hope..

I want to write a program which starts by gathering some information from the end user.
In my case it will be collecting a value between 0-24. I do this my means of a simple push button using : 'State Change Detection (Edge Detection)'

This value them needs to be used in the main Loop of my program.

The issue is, the button 'State Change Detection (Edge Detection)' program also requires the main void loop() to execute and run and gather the info from the user.

How can I run these two processes separately and have the value of the button read fed into my 'main loop()' program?

Any help will be much appreciated.

Here is the 'State Change Detection' code for reference as published on Arduino.cc


const int buttonPin = 7;
const int ledPin = 13;

int buttonPushCounter = 0; // counter for the number of button presses
int buttonState = 0; // current state of the button
int lastButtonState = 0; // previous state of the button

void setup() {
pinMode(buttonPin, INPUT);
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}

void loop() {

buttonState = digitalRead(buttonPin);

if (buttonState != lastButtonState) {
if (buttonState == HIGH) {
buttonPushCounter++;
Serial.println("on");
Serial.print("number of button pushes: ");
Serial.println(buttonPushCounter);
} else {
Serial.println("off");
}
delay(50);
}
lastButtonState = buttonState;

}


I really do not understand the question. The number of button pushes is always available in the butttonPushCounter variable, but how does the program know when the user is finished pushing the button? If you post the code that you have tried we might better understand what you are trying to accomplish.

Please read the "how to use the forum" stickies to see how to properly format and post code. It wouldn't hurt to read the "Read this before posting a programming question" at the top of the Programming Questions topic as well.

Have a look at the demo Planning and Implementing a Program. Very little of that program is actually in the loop() function.

...R