OK so I've got a project in the pipeline, ordered all my parts just waiting for them to arrive so i thought i do some theory crafting for the program and looking on the internet through tutorials i different places I haven't be able to find the information i was looking for!
(perhaps i fail at this "internet")
so basically I want a button press to do some motor movements (of which i think I've figured out) but i want the arduino to ignore all other button presses until it has completed said process. it there a way of doing this as i said I've had a shifty around the internet but not a lot of information jumped out at me.
You need to describe what you want to happen in more detail. Unless you can get some feedback from the motor(s) you will need to rely on timing to prevent he Arduino responding to further button presses.
Have you downloaded the IDE and installed it ? There is no reason why you could not start writing the program before you have the hardware. Obviously you will not be able to test it but you can at least verify that the code compiles.
but i want the arduino to ignore all other button presses until it has completed said process.
There is no ignoreThisButtonUntilToldNotTo() function. It is up to you to read, or not read, pin states (that may be controlled by switches) in an appropriate time/place/fashion.
In other words, don't read the states if you don't care about changes. Pin state changes are not pushed to the program; they are pulled by the program.
ok so here is a quick run down of what i have so far:
const int buttonPin = 2; // the number of the pushbutton pin
int buttonState = 0; // variable for reading the pushbutton status
int Distance1 = 0;
int Distance2 = 0;
void setup() {
pinMode(buttonPin, INPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
}
void loop()
{
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) // button press
{
digitalWrite(9, HIGH);
delay(1);
digitalWrite(9, LOW);
delay(1);
Distance1 = Distance1 +1 // moving forward motor1
If (Distance1 == 3600) // 2 Revs
{
digitalWrite(9, LOW); // stop motor1
delay(1)
digitalWrite(10, HIGH);
delay(1);
digitalWrite(10, LOW);
delay(1);
Distance2 = Distance2 +1// moving forward motor2
}
if (Distance2 == 800) // half rev
{
digitalWrite(10, LOW); // stop motor2
delay(5)
//Reverse Motor 2
// then reverse motor 1 back to start POS
}
else
{
// RED LED on
}
else
{
GREEN LED on
}
}
basically I don’t, want the program interrupted until its back to the beginning and I do not profess to being any good at coding and this program is unfinished obviously, but i don’t want to go on coding knowing i’m going down the wrong route.
Full marks for putting your code in code tags. I wish other newbies took the trouble.
If you use the autoformat button on the IDE it will line up your code so it is easier to read.
delay(1) will only delay for 1 millisecond. If you want a 1 second delay you need delay(1000).
Be conscious that the Arduino can do nothing else while it is waiting for delay() to expire. If that is a problem then the technique in the Blink Without Delay example sketch allows for time to be managed without using the delay() function. That way the Arduino can be doing something else while the time passes.
Back to the question at hand will a second button press interrupt the first or will it continue through the code?
No, a second switch press does not interrupt the program, unless you have connected the switch to an interrupt pin and written an interrupt handler. Even if you do that, when the interrupt handler ends, control returns to whatever the program was doing when the interrupt happened.
It will be well worthwhile to download the IDE. The code you supplied will not compile, as you have too many left curly braces. in it. When that happens, especially in a longish sketch, it's difficult to figure out just where you wanted the braces. You would know at least what you intended, and could make a better (well, easier) guess than we can. The IDE will tell you this when you auto-format, and will show you any errors you've made (except for logical design errors, of course).
lar3ry:
It will be well worthwhile to download the IDE. The code you supplied will not compile, as you have too many left curly braces. in it. When that happens, especially in a longish sketch, it's difficult to figure out just where you wanted the braces. You would know at least what you intended, and could make a better (well, easier) guess than we can. The IDE will tell you this when you auto-format, and will show you any errors you've made (except for logical design errors, of course).