Outils pour utilisateurs

Outils du site


start:arduino:manette_ps2

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentesRévision précédente
Prochaine révision
Révision précédente
start:arduino:manette_ps2 [2022/05/09 16:48] – [Interfaçage de la manette PS2 avec Arduino] gerardadminstart:arduino:manette_ps2 [2023/01/27 16:08] (Version actuelle) – modification externe 127.0.0.1
Ligne 39: Ligne 39:
 La ligne CLK et les lignes ATT du récepteur PS2 sont maintenues normalement hautes. L'ATT fonctionne comme la ligne Slave Select sous SPI. Vous le tirez vers le bas pour dire au contrôleur que vous lui parlez, puis le renvoyez vers le haut une fois qu'un cycle de communication est terminé. CMD est la ligne de données vers le contrôleur et DATA est les données provenant du contrôleur. Ici, dans notre application, nous n'utilisons pas la broche de reconnaissance. La ligne CLK et les lignes ATT du récepteur PS2 sont maintenues normalement hautes. L'ATT fonctionne comme la ligne Slave Select sous SPI. Vous le tirez vers le bas pour dire au contrôleur que vous lui parlez, puis le renvoyez vers le haut une fois qu'un cycle de communication est terminé. CMD est la ligne de données vers le contrôleur et DATA est les données provenant du contrôleur. Ici, dans notre application, nous n'utilisons pas la broche de reconnaissance.
  
-Eh bien, c'était tellement jusqu'ici, alors voici la photo de ce que nous avons réellement fait avec ce contrôleur PS2 vraiment génial et le code du projet exécuté sur Arduino :+<code PS2_Arduino.ino> 
 +#include <PS2X_lib.h>                         /PS2 Controller Library */ 
 +PS2X ps2x;                                    /* create PS2 Controller Class*/ 
 +byte Type = 0; 
 +byte vibrate = 0; 
 +int rx=0,ry=0,lx=0,ly=0;
  
 +void setup(){
 +   Serial.begin(9600);
 +   ps2x.config_gamepad(13,11,10,12, true, true); /* setup pins and settings:  GamePad(clock, command, attention, data, Pressures?, Rumble?) check for error*/
 +   Type = ps2x.readType();                       /* Reading type of the PS2 Ccontroller */
 +   if(Type==1){                                  /* Type 1 is Duel shock controller */ 
 +   
 +      Serial.println("   DualShock    ");             /* display if the controller is duel shock*/
 +      
 +      Serial.println("Controller Found");
 +      delay(1000);
 +     
 +   }
 +}
 +void loop(){
  
 +   ps2x.read_gamepad(false, vibrate);   /* read controller and set large motor to spin at 'vibrate' speed */
 +   
 +   Serial.println("Stick values:   ");       /* Display analog stick values */
 +   
 +   ly = ps2x.Analog(PSS_LY);          /* Reading Left stick Y axis */
 +   lx = ps2x.Analog(PSS_LX);          /* Reading Left stick X axis */
 +   ry = ps2x.Analog(PSS_RY);          /* Reading Right stick Y axis */
 +   rx = ps2x.Analog(PSS_RX);          /* Reading Right stick X axis */
 +   
 +   if((ly <= 9))                      /* standardize to 3 digit by checking less than 10 */
 +      Serial.println("00");                /* eg: if ly= 5 then it display as "005" in Serial */
 +   if((ly >= 9 &&ly <= 99))           /* standardize to 3 digit by checking between 10-99 */
 +      Serial.print("0");                 /* eg: if ly= 55 then it display as "055" in Serial */     
 +   Serial.println(ly,DEC);                 /* display left analog stick Y axis */
 +   Serial.print(",");                    /* separate values using comma */
 +   if((lx <= 9))                      /* standardize to 3 digit by checking less than 10 */
 +      Serial.print("00");                /* eg: if lx= 5 then it display as "005" in Serial */
 +   if((lx >= 9 && lx<=99))            /* standardize to 3 digit by checking between 10-99 */
 +      Serial.println("0");                 /* eg: if lx= 55 then it display as "055" in Serial */  
 +   Serial.println(lx,DEC);                 /* display left analog stick X axis */
 +   Serial.print(",");                    /* separate values using comma */
 +   if((ry <= 9))                      /* standardize to 3 digit by checking less than 10 */
 +      Serial.println("00");                /* eg: if rx= 5 then it display as "005" in Serial */
 +   if((ry >= 9 &&rx<=99))             /* standardize to 3 digit by checking between 10-99 */
 +      Serial.println("0");                 /* eg: if rx= 55 then it display as "055" in Serial */  
 +   Serial.println(ry,DEC);                 /* display Right analog stick Y axis               */
 +   Serial.println(",");                    /* separate values using comma */
 +   if((rx <= 9))                      /* standardize to 3 digit by checking less than 10 */
 +      Serial.println("00");                /* eg: if RX= 5 then it display as "005" in Serial */
 +   if((rx >= 9 &&rx <= 99))           /* standardize to 3 digit by checking between 10-99 */
 +      Serial.println("0");                 /* eg: if RX= 55 then it display as "055" in Serial */  
 +   Serial.println(rx,DEC);                 /* display Right analog stick X axis          */
 +   Serial.println(" ");
 +   if(ps2x.NewButtonState()) {        /* will be TRUE if any button changes state  */
 +      
 +      if(ps2x.Button(PSB_START))      /* will be TRUE as long START button is pressed */
 +         Serial.println("START PRESSED   ");
 +      if(ps2x.Button(PSB_SELECT))             /* will be TRUE as long SELECT button is pressed */
 +         Serial.println("SELECT PRESSED  ");
 +      if(ps2x.Button(PSB_PAD_UP))             /* will be TRUE as long as UP button is pressed */
 +         Serial.println("UP PRESSED      "); 
 +      if(ps2x.Button(PSB_PAD_RIGHT))          /* will be TRUE as long as UP button is pressed */
 +         Serial.println("RIGHT PRESSED   ");
 +      if(ps2x.Button(PSB_PAD_LEFT))           /* will be TRUE as long as LEFT button is pressed */
 +         Serial.println("LEFT PRESSED    "); 
 +      if(ps2x.Button(PSB_PAD_DOWN))           /* will be TRUE as long as DOWN button is pressed */
 +         Serial.println("DOWN PRESSED    "); 
 +      if(ps2x.Button(PSB_L1))                 /* will be TRUE as long as L1 button is pressed */
 +         Serial.println("L1 pressed      ");
 +      if(ps2x.Button(PSB_R1))                 /* will be TRUE as long as R1 button is pressed */
 +         Serial.println("R1 pressed      "); 
 +      if(ps2x.Button(PSB_L2))                 /* will be TRUE as long as L2 button is pressed */
 +         Serial.println("L2 pressed      ");
 +      if(ps2x.Button(PSB_R2))                 /* will be TRUE as long as R2 button is pressed */
 +         Serial.println("R2 pressed      ");
 +      if(ps2x.Button(PSB_L3))                 /* will be TRUE as long as L3 button is pressed */
 +         Serial.println("L3 pressed      ");
 +      if(ps2x.Button(PSB_R3))                 /* will be TRUE as long as R3 button is pressed */
 +         Serial.println("R3 pressed      ");
 +      if(ps2x.Button(PSB_GREEN))              /* will be TRUE as long as GREEN/Triangle button is pressed */
 +         Serial.println("Triangle pressed");
 +      if(ps2x.Button(PSB_BLUE))                /* will be TRUE as long as BLUE/CROSS/X button is pressed */
 +         Serial.println("X pressed       "); 
 +       if(ps2x.Button(PSB_RED))               /* will be TRUE as long as RED/Circle button is pressed */
 +         Serial.println("Circle pressed  "); 
 +      if(ps2x.Button(PSB_PINK))               /* will be TRUE as long as PINK/Squre button is pressed */
 +         Serial.println("Square pressed  "); 
 +      delay(700);
 +   }
 +   else;
 +}
  
 +</code>
  
 +
 +===== Liens Manette PS2 <--> Arduino  =====
 +
 +[[https://electrotuto.com/2014/04/24/manette-ps2-et-arduino-ps2-controler/|manette-ps2-et-arduino-ps2-controler]]
 +
 +[[https://github.com/madsci1016/Arduino-PS2X| Librairie Arduino-PS2X]]
 +
 +
 +===== PS2 - Touches =====
 +
 +{{ :start:arduino:ps2_touches.jpg?direct&600 |}}
 +
 +
 +Les fonctions les plus pratiques de cette librairie sont :
 +
 +    ***ps2x.config_gamepad(clock, command, attention, data, Pressures? Rumble?);**
 + La fonction définit la broche du contrôleur et la sensibilité à la pression et aux vibrations des moteurs. Si vous voulez que les touches soient insensibles à la pression ou que les moteurs n'aient pas de vibrations, définissez Pressures et Rumble sur false. Cette fonction renvoie une valeur pour l'erreur
 +
 +    ***ready();**
 +La fonction détermine le type de contrôleur détecté. 0 signifie que le contrôleur n'est pas détecté correctement, 1 signifie la détection du contrôleur DualShock et 2 signifie la détection du contrôleur GuitarHero.
 +
 +    ***read_gamepad(boolean motor1, byte motor2);** 
 +La fonction commencer à lire l'état des touches lorsque l'état de la vibration du moteur est déterminé. (le moteur 2 est le plus gros.)
 +
 +    ***Button (but type);** 
 +la fonction renvoie 1 lorsque la touche spécifique de l'argument de la fonction est enfoncée. Dans DualShock, les touches du contrôleur sont nommées comme suit :
 +
 +{{ :start:arduino:ps2_touches_signification.jpg?direct&600 |}}
 +
 +
 +
 +===== Robot Arduino avec manette PS2 (Joystick PlayStation 2)  =====
 +
 +[[http://fr.mfgrobots.com/mfg/mpm/1002017506.html|Manette PS2 SSfils et arduino]]
 +
 +{{ :start:arduino:ps2-arduino_ssfils.jpg?direct&600 |}}
 +
 +
 +===== Radiocommande PS2 arduino nrf24l01 =====
 +
 +[[https://electrotuto.com/2014/10/09/realiser-une-radiocommande-avec-arduino-manette-ps2-et-nrf24l01/|Radiocommande PS2 arduino nrf24l01]]
/home/chanteri/www/fablab37110/data/attic/start/arduino/manette_ps2.1652107700.txt.gz · Dernière modification : 2023/01/27 16:08 (modification externe)