ENIB 2022 - groupe D : CandyGrabber : Différence entre versions

De Les Fabriques du Ponant
Aller à : navigation, rechercher
(photo de l'équipe)
(Code)
Ligne 25 : Ligne 25 :
 
ici je pose mon code documenté !
 
ici je pose mon code documenté !
 
</pre>
 
</pre>
 +
 +
/* Inclut la lib Servo pour manipuler le servomoteur */
 +
#include "Servo.h"
 +
/* Créer un objet Servo pour contrôler le servomoteur */
 +
Servo monServomoteur;
 +
Servo monServomoteur2;
 +
 +
void setup(){
 +
  // Attache le servomoteur à la broche D9
 +
  monServomoteur.attach(8);
 +
  monServomoteur2.attach(9);
 +
  monServomoteur.write(90);
 +
  monServomoteur2.write(90);
 +
  pinMode(5,INPUT);//activation led bleu pour simuler le piston
 +
  pinMode(6,OUTPUT);//activation led rouge pour simuler la descente de la pince
 +
  pinMode(7,INPUT);//bouton poussoir
 +
  digitalWrite(7,HIGH);//on active la résistance de pull-up
 +
  pinMode(A6,INPUT);//vrx
 +
  pinMode(A7,INPUT);//vry
 +
 
 +
  Serial.begin(9600);
 +
  }
 +
 +
void loop() {
 +
  // put your main code here, to run repeatedly:
 +
  int BP=digitalRead(7);
 +
  Serial.println(BP);
 +
  double VRx = analogRead(A6);
 +
  double VRy = analogRead(A7);
 +
  int c;
 +
  int x=0;
 +
  int y=10;
 +
  Serial.println(VRx);
 +
  //if (BP){ //si BP est à 1 donc  non appuyer
 +
   
 +
  //On test la position en x
 +
  if (VRx<400){
 +
    x=1;
 +
  }
 +
  if(VRx>600){
 +
    x=2;
 +
  }
 +
  //on test la position en y
 +
  if (VRy<400){
 +
    y=13;
 +
  }
 +
  if(VRy>600){
 +
    y=16;
 +
  }
 +
  //on definie une variable intermediaire
 +
  c=x+y;
 +
 
 +
  switch (c) {
 +
    //cas 1 gauche
 +
  case 11:
 +
    monServomoteur.write(180);
 +
    monServomoteur2.write(90);
 +
    delay(10);
 +
    break;
 +
    //cas 2 droite
 +
  case 12:
 +
    monServomoteur.write(0);
 +
    monServomoteur2.write(90);
 +
    delay(10);
 +
    break;
 +
    //cas 3 gauche
 +
  case 13:
 +
    monServomoteur2.write(180);
 +
    monServomoteur.write(90);
 +
    delay(10);
 +
    break;
 +
    //cas 4 gauche et gauche
 +
  case 14:
 +
    monServomoteur.write(180);
 +
    monServomoteur2.write(180);
 +
    delay(10);
 +
    break;
 +
    //cas 5 gauche et droite
 +
  case 15:
 +
    monServomoteur.write(0);
 +
    monServomoteur2.write(180);
 +
    delay(10);
 +
    break;
 +
    //cas 6 droite Y
 +
  case 16:
 +
    monServomoteur2.write(0);
 +
    monServomoteur.write(90);
 +
    delay(10);
 +
    break;
 +
    //cas 7 x gauche et y droite
 +
  case 17:
 +
    monServomoteur.write(180);
 +
    monServomoteur2.write(0);
 +
    delay(10);
 +
    break;
 +
    //cas 8
 +
  case 18:
 +
    monServomoteur2.write(0);
 +
    monServomoteur.write(0);
 +
    delay(10);
 +
    break;
 +
  default:
 +
    monServomoteur.write(90);
 +
    monServomoteur2.write(90);
 +
    delay(10);
 +
    break;
 +
}
 +
}
 +
}
  
 
==Catégories==
 
==Catégories==
  
 
[[Catégorie:Enib2022]]
 
[[Catégorie:Enib2022]]

Version du 17 janvier 2022 à 15:39

photo de l'équipe

La famille.jpg

Que fait ce projet ?

Candy Grabber est une pince qui attrape des bonbon dans une boite. Cette pince se déplace grâce à un joystick.

Liste des composants

  • Cable de montage
  • 1 moteur 5V
  • 1 mini breadboard
  • 1 Bouton poussoir
  • 1 carte nano Arduino (avec cable d'alimentation)
  • 1 mini version électronique
  • 1 mini vérin électrique
  • 1 joystick
  • 1 contrôleur moteur
  • 2 cerveaux moteurs
  • 3 tiges en métal
  • planches de bois

Code

ici je pose mon code documenté !

/* Inclut la lib Servo pour manipuler le servomoteur */

  1. include "Servo.h"

/* Créer un objet Servo pour contrôler le servomoteur */ Servo monServomoteur; Servo monServomoteur2;

void setup(){

 // Attache le servomoteur à la broche D9 
 monServomoteur.attach(8);
 monServomoteur2.attach(9);
 monServomoteur.write(90);
 monServomoteur2.write(90);
 pinMode(5,INPUT);//activation led bleu pour simuler le piston
 pinMode(6,OUTPUT);//activation led rouge pour simuler la descente de la pince
 pinMode(7,INPUT);//bouton poussoir
 digitalWrite(7,HIGH);//on active la résistance de pull-up
 pinMode(A6,INPUT);//vrx
 pinMode(A7,INPUT);//vry
 
 Serial.begin(9600);
 }

void loop() {

 // put your main code here, to run repeatedly:
 int BP=digitalRead(7);
 Serial.println(BP);
 double VRx = analogRead(A6);
 double VRy = analogRead(A7);
 int c;
 int x=0;
 int y=10;
 Serial.println(VRx);
 //if (BP){ //si BP est à 1 donc  non appuyer
   
 //On test la position en x
 if (VRx<400){
   x=1;
 }
 if(VRx>600){
   x=2;
 }
 //on test la position en y
 if (VRy<400){
   y=13;
 }
 if(VRy>600){
   y=16;
 }
 //on definie une variable intermediaire
 c=x+y;
 
 switch (c) {
   //cas 1 gauche
 case 11:
   monServomoteur.write(180);
   monServomoteur2.write(90);
   delay(10);
   break;
   //cas 2 droite
 case 12:
   monServomoteur.write(0);
   monServomoteur2.write(90);
   delay(10);
   break;
   //cas 3 gauche
 case 13:
   monServomoteur2.write(180);
   monServomoteur.write(90);
   delay(10);
   break;
   //cas 4 gauche et gauche
 case 14:
   monServomoteur.write(180);
   monServomoteur2.write(180);
   delay(10);
   break;
   //cas 5 gauche et droite
 case 15:
   monServomoteur.write(0);
   monServomoteur2.write(180);
   delay(10);
   break;
   //cas 6 droite Y
 case 16:
   monServomoteur2.write(0);
   monServomoteur.write(90);
   delay(10);
   break;
   //cas 7 x gauche et y droite
 case 17:
   monServomoteur.write(180);
   monServomoteur2.write(0);
   delay(10);
   break;
   //cas 8
 case 18:
   monServomoteur2.write(0);
   monServomoteur.write(0);
   delay(10);
   break;
 default:
   monServomoteur.write(90);
   monServomoteur2.write(90);
   delay(10);
   break;

} } }

Catégories