Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created February 15, 2020 04:34
Show Gist options
  • Save parzibyte/50fe35760389fe47641da27b85806d05 to your computer and use it in GitHub Desktop.
Save parzibyte/50fe35760389fe47641da27b85806d05 to your computer and use it in GitHub Desktop.
// Leer del joystick
int obtenerDireccion() {
int valorX = analogRead(pinX),
valorY = analogRead(pinY);
if (valorX > 1000) {
return DIRECCION_ARRIBA;
} else if (valorX < 200) {
return DIRECCION_ABAJO;
}
if (valorY > 1000) {
return DIRECCION_DERECHA;
} else if (valorY < 200) {
return DIRECCION_IZQUIERDA;
}
// Regresamos algo inválido, pues no se cambió,
// y dependemos de la función cambiarDireccion
return -1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment