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;
}