Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save tornikegomareli/7b65cbf395a70366ce9557597305a5d4 to your computer and use it in GitHub Desktop.
Save tornikegomareli/7b65cbf395a70366ce9557597305a5d4 to your computer and use it in GitHub Desktop.
Arduino motor controller
const int buttonPin = 5; // button
const int motorPin = 10; // motor
const int impulsePin = 7; // impulse
boolean switch_on = false;
int buttonState = 0; // variable for listening button
int impulseState = 0; // varaible for listening impulse
int counter = 0;
int monets_rushing_stop = 2; // number for changing
void setup() {
pinMode(motorPin,OUTPUT);
pinMode(buttonPin,INPUT);
}
void loop() {
buttonState = digitalRead(buttonPin);
if(buttonState == HIGH) {
if(switch_on == true) {
switch_on = false;
}
else {
switch_on = true;
}
}
if((switch_on == true) && (counter < monets_rushing_stop)) {
digitalWrite(motorPin,HIGH);
impulseState = digitalRead(impulsePin);
if(impulseState == HIGH) {
counter++;
Serial.print(counter);
}
}
else {
counter = 0;
switch_on = false;
digitalWrite(motorPin,LOW);
}
delay(500);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment