Skip to content

Instantly share code, notes, and snippets.

@ferclaverino
Last active December 27, 2015 18:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ferclaverino/7370914 to your computer and use it in GitHub Desktop.
Save ferclaverino/7370914 to your computer and use it in GitHub Desktop.
Una grúa controlada con un único botón
#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