int INA = 9; //pin connected to INA
int INB = 10; // pin connected to INB
int button = 11; // pin connected to button
int button_presses = 0; //button press counter
void setup() {
//declare pin modes
pinMode(INA,OUTPUT);
pinMode(INB,OUTPUT);
pinMode(button,INPUT);
}
void loop() {
// raise button counter if button pressed
if(digitalRead(button) == 1){
button_presses ++;
delay(10)
}
//turn the fan right if button has been pressed 1 time
if(button_presses == 1){
analogWrite(INA,255);
digitalWrite(INB,0);
}
//turn the fan left if button has been pressed 2 times
if(button_presses == 2){
analogWrite(INB,255);
digitalWrite(INA,0);
}
//turn fan off if button has been pressed 3 times
if(button_presses == 3){
digitalWrite(INA,0);
digitalWrite(INB,0);
}
//reset button counter
if(button_presses >= 3){
button_presses = 0;
}
}
The pushbutton will be seen many many times per second, and when pressed button_presses will skitter around and around, where it stops is nobody's guess.
So unless you were going for a frustrating game, no.
Your three topics on the same or similar subject have been merged.
Please do not duplicate your questions as doing so wastes the time and effort of the volunteers trying to help you as they are then answering the same thing in different places.
Please create one topic only for your question and choose the forum category carefully. If you have multiple questions about the same project then please ask your questions in the one topic as the answers to one question provide useful context for the others, and also you won’t have to keep explaining your project repeatedly.
Repeated duplicate posting could result in a temporary or permanent ban from the forum.
Could you take a few moments to Learn How To Use The Forum
It will help you get the best out of the forum in the future.
I'm sorry everybody for disregard to the rules of the forum, I've taken time to read through the rules and now know how to maintain peace within the forum.