Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@LeoColomb
Created November 16, 2012 21:48
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 LeoColomb/4091214 to your computer and use it in GitHub Desktop.
Save LeoColomb/4091214 to your computer and use it in GitHub Desktop.
Déplacement Mobile - Arduino
/****
* Déplacement de Mobile
* Moteur + Relais
*
* Léo Colombaro - 2012
****/
// LED de controle
int Led = 9;
// Direction et actionnement du moteur
int dir = 7;
int go = 6;
// INPUT de controle de fin de course
int checkCourse = 8;
// Tableaux des parametres : Temps de marche,
// Direction (1=avnancé;0=retour), Temps de pause
int time[] = {
6, 3, 6, 7};
int motorDir[] = {
1, 0, 1, 0};
int pauseDelay[] = {
10, 70, 2000, 100};
// Taille des tableaux, nombre de tours dans la boucle
int loopMax = (sizeof(motorDir)/sizeof(int)) - 1;
// Initialisation
int i = 0;
// debug
int DEBUG = 0;
void setup() {
pinMode(Led, OUTPUT);
pinMode(go, OUTPUT);
pinMode(dir, OUTPUT);
pinMode(checkCourse, INPUT_PULLUP);
if (DEBUG){
Serial.begin(9600);
}
}
void loop() {
// pause initiale
delay(pauseDelay[i]);
// definition de la direction
digitalWrite(dir, motorDir[i]);
delay(20);
// mouvement
digitalWrite(Led, LOW);
digitalWrite(go, HIGH);
// durée de mouvement
delay(time[i]*1000);
// stop
digitalWrite(go, LOW);
digitalWrite(Led, HIGH);
// debug info
Serial.println(i);
Serial.println(digitalRead(checkCourse));
// fin de cycle de la boucle
if (i >= loopMax){
// fin de course
if (digitalRead(checkCourse) == LOW) {
i = 0;
}
}
else {
i++;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment