Actions
h1. Gestionnaire Petit Robot
/* Programme gestionnaire du Petit Robot Justin CANO, le 7-12-2015 I - Constantes globales */ int declenchement = 2; int parasol = 3; int belierFin = 4; int capteurG = A0; int capteurD = A1; int capteurA = A2; float vitesseTranslation=0.0; float vitesseRotation=0.0; //communication i2c boolean req=false; #include // II - Méthodes void setup () { pinMode(parasol,OUTPUT); Wire.begin(8); // join i2c bus with address #8 Wire.onReceive(receiveEvent); // register event Wire.onRequest(requestEvent); //request event } void loop () { principal(); } void principal () { boolean depart = digitalRead(declenchement); //déclenchement du programme lorqu'un état haut se présente au robot boolean a = true; moteurZero(); long tdepart; while(depart) { if(a) { tdepart = millis(); // l'échelle de temps commence ici (décompte des 90 s) est initialisée UNE fois } a=false; //on interdit la réinitialisation long t=millis(); // mesure du temps absolu if(t-tdepart<90000) { //durant le match fermePorte(); } else { // après le match moteurZero(); ouvreParasol(); } delayMicroseconds(20); //petit delay pour la forme } delayMicroseconds(20); //petit delay pour la forme } void fermePorte() { // fermeture des portes par contour du décor // A DETERMINER } float distanceIr(int tensionCodee) { // Distance en mm donnée par l'IR avec pour entrée un digital Read return 0.0; } void moteurZero() { //ordonne l'arrêt de ces derniers } void ouvreParasol() {//ouverture du parasol } void receiveEvent(int howMany) { float variationMotorG; float variationMotorD; while (1 < Wire.available()) { // loop through all but the last int c = Wire.read(); // receive byte as a character //Serial.print(c); // print the character variationMotorG=((float) c)/10.0; } while (Wire.available()) { // loop through all but the last int c = Wire.read(); // receive byte as a character //Serial.print(c); // print the character variationMotorD=((float) c)/10.0; } } void requestEvent() { if (req==false) { int translation=(int)(vitesseTranslation*10.0); Wire.write(translation); //Serial.print(i); //Serial.print(" "); req=true; } else if (req==true) { int rotation= (int)(vitesseRotation*100.0); req=false; Wire.write(rotation); //Serial.println(x); } }
Mis à jour par Anonyme il y a plus de 9 ans · 1 révisions