Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const int button = 4; // Limit switch
- const int button2 = 2; // Limit Switch
- const int button3 = 13; // Start signal
- const int motorPin = 8; // L298 IN2
- const int motorPin2 = 7; // L298 IN1
- boolean buttonstatus = 0;
- boolean buttonstatus2 = 0;
- boolean buttonstatus3 = 0;
- int drawPosition = 2;
- void setup() {
- pinMode(motorPin, OUTPUT);
- pinMode(motorPin2, OUTPUT);
- pinMode(button, INPUT);
- pinMode(button2, INPUT);
- pinMode(button3, INPUT);
- // if the power fails close gate
- digitalWrite(motorPin, HIGH);
- digitalWrite(motorPin2, LOW);
- }
- void drawForward() {
- digitalWrite(motorPin, LOW);
- digitalWrite(motorPin2, HIGH);
- }
- void drawBackward() {
- // turn motor in other direction:
- digitalWrite(motorPin, HIGH);
- digitalWrite(motorPin2, LOW);
- }
- void stopDrawFromMoving() {
- digitalWrite(motorPin, LOW);
- digitalWrite(motorPin2, LOW);
- }
- void loop() {
- buttonstatus = digitalRead(button);
- buttonstatus2 = digitalRead(button2);
- buttonstatus3 = digitalRead(button3);
- if (buttonstatus == HIGH) {
- drawPosition = 2;
- stopDrawFromMoving();
- }else if (buttonstatus2 == HIGH) {
- drawPosition = 1;
- stopDrawFromMoving();
- }
- if (buttonstatus3 == HIGH) {
- if (drawPosition == 2 ) {
- delay(100);
- drawForward();
- delay(100);
- drawPosition = 1;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement