Created
March 14, 2017 21:20
-
-
Save tornikegomareli/7b65cbf395a70366ce9557597305a5d4 to your computer and use it in GitHub Desktop.
Arduino motor controller
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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