Created
April 25, 2017 22:43
-
-
Save Maes95/cd2a03825e7c3c89b350ab87f02337db to your computer and use it in GitHub Desktop.
SETR
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
void delanteDerecha(int velocidad){ | |
Serial.print("Delante derecha!"); | |
controlMotor("del_der", 1, 0); | |
controlMotor("del_izq", 1, velocidad); | |
controlMotor("atr_der", 1, velocidad); | |
controlMotor("atr_izq", 1, 0); | |
} | |
void controlMotor(String motorStr,int mdirection, int velocidad){ | |
int IN1; | |
int IN2; | |
int motorPWM; | |
if (motorStr == "del_der") { // Motor delante derecha | |
IN1 = AIN1_DelanteDerecha; | |
IN2 = AIN2_DelanteDerecha; | |
motorPWM = PWM_DelanteDerecha; | |
} | |
else if (motorStr == "del_izq") { // Motor delante izquierda | |
IN1 = BIN1_DelanteIzquierda; | |
IN2 = BIN2_DelanteIzquierda; | |
motorPWM = PWM_DelanteIzquierda; | |
} | |
else if (motorStr == "atr_der") { // Motor atrás derecha | |
IN1 = AIN1_AtrasDerecha; | |
IN2 = AIN2_AtrasDerecha; | |
motorPWM = PWM_AtrasDerecha; | |
} | |
else if (motorStr == "atr_izq") { // Motor atrás izquierda | |
IN1 = BIN1_AtrasIzquierda; | |
IN2 = BIN2_AtrasIzquierda; | |
motorPWM = PWM_AtrasIzquierda; | |
} | |
if (mdirection == 1){ | |
Serial.print("Hacia delante"); | |
digitalWrite(IN1, LOW); | |
digitalWrite(IN2, HIGH); | |
} | |
else if (mdirection == -1){ | |
Serial.print("Hacia atrás"); | |
digitalWrite(IN1, HIGH); | |
digitalWrite(IN2, LOW); | |
} | |
analogWrite(motorPWM, velocidad); | |
} |
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
void leerTecla (){ | |
// <code> | |
byte character = Serial1.read(); | |
// <code> | |
case 'c': // Delante derecha | |
delanteDerecha(VELOCITY); | |
break; | |
} |
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
void loop(){ | |
// SOLO SI BLUETOOTH DISPONIBLE... | |
if (Serial1.available()) { | |
leerTecla(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment