Hello everyone, I am an new to Arduino but really excited about it.
I have a problem that I have yet to figure out, I have a button "digitalRead(22)" that when something is put on top of it will initiate the code in the for loop, making the motor move a certain amount of rotations. What I need is that once pressed the code will only execute once and ignore any more reading of digitalRead(22) == LOW so that the motor won't keep moving. I only need it to read the value once the button is pressed and then after runt he code and ignore any other instances of it being low.
int servoPin = 9;
int servoPosition = 2000; // position in microseconds
int i=0;
void setup() {
//Serial.begin(9600);
pinMode(servoPin, OUTPUT);
pinMode(22,INPUT);
}
void loop(){
if(digitalRead(22) == LOW) //Button has been pressed
{
for(i=0; i<31; i++)
{
digitalWrite(servoPin, HIGH);
delayMicroseconds(servoPosition);
digitalWrite(servoPin, LOW);
delay(175); // wait 175 milliseconds
}
}
}