Last active
December 27, 2015 18:39
-
-
Save ferclaverino/7370914 to your computer and use it in GitHub Desktop.
Una grúa controlada con un único botón
This file contains hidden or 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
#include <MotorShield.h> | |
const int buttonPin = 2; | |
const int ledPin = 13; | |
MS_DCMotor motor(MOTOR_A); | |
int buttonState = 0; | |
int gruaState = 0; | |
void setup() { | |
pinMode(ledPin,OUTPUT); | |
pinMode(buttonPin,INPUT); | |
motor.run(BRAKE); | |
motor.setSpeed(255); | |
} | |
void loop() { | |
buttonState = digitalRead(buttonPin); | |
if (buttonState == HIGH) { | |
digitalWrite(ledPin, HIGH); | |
if(gruaState==HIGH){ | |
motor.run(FORWARD|RELEASE); | |
} else { | |
motor.run(BACKWARD|RELEASE); | |
} | |
} else { | |
digitalWrite(ledPin, LOW); | |
motor.run(BRAKE); | |
if(gruaState==HIGH){ | |
gruaState=LOW; | |
} else { | |
gruaState=HIGH; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment