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 17:04] gerardadminstart:arduino:manette_ps2 [2023/01/27 16:08] (Version actuelle) – modification externe 127.0.0.1
Ligne 41: Ligne 41:
 <code c PS2_Arduino.ino> <code c PS2_Arduino.ino>
 #include <PS2X_lib.h>                         /* PS2 Controller Library */ #include <PS2X_lib.h>                         /* PS2 Controller Library */
- 
 PS2X ps2x;                                    /* create PS2 Controller Class*/ PS2X ps2x;                                    /* create PS2 Controller Class*/
 byte Type = 0; byte Type = 0;
 byte vibrate = 0; byte vibrate = 0;
-int RX=0,RY=0,LX=0,LY=0; +int rx=0,ry=0,lx=0,ly=0; 
-LiquidCrystal lcd(2,3,7, 6, 5, 4);            /* initialize the library with the numbers of the interface pins*/+
 void setup(){ void setup(){
    Serial.begin(9600);    Serial.begin(9600);
Ligne 52: Ligne 51:
    Type = ps2x.readType();                       /* Reading type of the PS2 Ccontroller */    Type = ps2x.readType();                       /* Reading type of the PS2 Ccontroller */
    if(Type==1){                                  /* Type 1 is Duel shock controller */     if(Type==1){                                  /* Type 1 is Duel shock controller */ 
-      lcd.print("   DualShock    ");             /* display if the controller is duel shock*/ +    
-      lcd.setCursor(0, 1) ; +      Serial.println("   DualShock    ");             /* display if the controller is duel shock*/ 
-      lcd.print("Controller Found");+       
 +      Serial.println("Controller Found");
       delay(1000);       delay(1000);
-      lcd.clear(); +     
    }    }
 } }
Ligne 62: Ligne 62:
  
    ps2x.read_gamepad(false, vibrate);   /* read controller and set large motor to spin at 'vibrate' speed */    ps2x.read_gamepad(false, vibrate);   /* read controller and set large motor to spin at 'vibrate' speed */
-   lcd.setCursor(0, 0);                 /* Position the LCD cursor */ +    
-   lcd.print("Stick values:   ");       /* Display analog stick values */ +   Serial.println("Stick values:   ");       /* Display analog stick values */ 
-   lcd.setCursor(0, 1); +    
-   LY = ps2x.Analog(PSS_LY);          /* Reading Left stick Y axis */ +   ly = ps2x.Analog(PSS_LY);          /* Reading Left stick Y axis */ 
-   LX = ps2x.Analog(PSS_LX);          /* Reading Left stick X axis */ +   lx = ps2x.Analog(PSS_LX);          /* Reading Left stick X axis */ 
-   RY = ps2x.Analog(PSS_RY);          /* Reading Right stick Y axis */ +   ry = ps2x.Analog(PSS_RY);          /* Reading Right stick Y axis */ 
-   RX = ps2x.Analog(PSS_RX);          /* Reading Right stick X axis */ +   rx = ps2x.Analog(PSS_RX);          /* Reading Right stick X axis */ 
-   if((LY <= 9))                      /* standardize to 3 digit by checking less than 10 */ +    
-      lcd.print("00");                /* eg: if LY= 5 then it display as "005" in lcd */ +   if((ly <= 9))                      /* standardize to 3 digit by checking less than 10 */ 
-   if((LY >= 9 &&LY <= 99))           /* standardize to 3 digit by checking between 10-99 */ +      Serial.println("00");                /* eg: if ly= 5 then it display as "005" in Serial */ 
-      lcd.print("0");                 /* eg: if LY= 55 then it display as "055" in lcd */      +   if((ly >= 9 &&ly <= 99))           /* standardize to 3 digit by checking between 10-99 */ 
-   lcd.print(LY,DEC);                 /* display left analog stick Y axis */ +      Serial.print("0");                 /* eg: if ly= 55 then it display as "055" in Serial */      
-   lcd.print(",");                    /* separate values using comma */ +   Serial.println(ly,DEC);                 /* display left analog stick Y axis */ 
-   if((LX <= 9))                      /* standardize to 3 digit by checking less than 10 */ +   Serial.print(",");                    /* separate values using comma */ 
-      lcd.print("00");                /* eg: if LX= 5 then it display as "005" in lcd */ +   if((lx <= 9))                      /* standardize to 3 digit by checking less than 10 */ 
-   if((LX >= 9 && LX<=99))            /* standardize to 3 digit by checking between 10-99 */ +      Serial.print("00");                /* eg: if lx= 5 then it display as "005" in Serial */ 
-      lcd.print("0");                 /* eg: if LX= 55 then it display as "055" in lcd */   +   if((lx >= 9 && lx<=99))            /* standardize to 3 digit by checking between 10-99 */ 
-   lcd.print(LX,DEC);                 /* display left analog stick X axis */ +      Serial.println("0");                 /* eg: if lx= 55 then it display as "055" in Serial */   
-   lcd.print(",");                    /* separate values using comma */ +   Serial.println(lx,DEC);                 /* display left analog stick X axis */ 
-   if((RY <= 9))                      /* standardize to 3 digit by checking less than 10 */ +   Serial.print(",");                    /* separate values using comma */ 
-      lcd.print("00");                /* eg: if RY= 5 then it display as "005" in lcd */ +   if((ry <= 9))                      /* standardize to 3 digit by checking less than 10 */ 
-   if((RY >= 9 &&RY<=99))             /* standardize to 3 digit by checking between 10-99 */ +      Serial.println("00");                /* eg: if rx= 5 then it display as "005" in Serial */ 
-      lcd.print("0");                 /* eg: if RY= 55 then it display as "055" in lcd */   +   if((ry >= 9 &&rx<=99))             /* standardize to 3 digit by checking between 10-99 */ 
-   lcd.print(RY,DEC);                 /* display Right analog stick Y axis               */ +      Serial.println("0");                 /* eg: if rx= 55 then it display as "055" in Serial */   
-   lcd.print(",");                    /* separate values using comma */ +   Serial.println(ry,DEC);                 /* display Right analog stick Y axis               */ 
-   if((RX <= 9))                      /* standardize to 3 digit by checking less than 10 */ +   Serial.println(",");                    /* separate values using comma */ 
-      lcd.print("00");                /* eg: if RX= 5 then it display as "005" in lcd */ +   if((rx <= 9))                      /* standardize to 3 digit by checking less than 10 */ 
-   if((RX >= 9 &&RX <= 99))           /* standardize to 3 digit by checking between 10-99 */ +      Serial.println("00");                /* eg: if RX= 5 then it display as "005" in Serial */ 
-      lcd.print("0");                 /* eg: if RX= 55 then it display as "055" in lcd */   +   if((rx >= 9 &&rx <= 99))           /* standardize to 3 digit by checking between 10-99 */ 
-   lcd.print(RX,DEC);                 /* display Right analog stick X axis          */ +      Serial.println("0");                 /* eg: if RX= 55 then it display as "055" in Serial */   
-   lcd.print(" ");+   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.NewButtonState()) {        /* will be TRUE if any button changes state  */
-      lcd.setCursor(0, 0);+      
       if(ps2x.Button(PSB_START))      /* will be TRUE as long START button is pressed */       if(ps2x.Button(PSB_START))      /* will be TRUE as long START button is pressed */
-         lcd.print("START PRESSED   ");+         Serial.println("START PRESSED   ");
       if(ps2x.Button(PSB_SELECT))             /* will be TRUE as long SELECT button is pressed */       if(ps2x.Button(PSB_SELECT))             /* will be TRUE as long SELECT button is pressed */
-         lcd.print("SELECT PRESSED  ");+         Serial.println("SELECT PRESSED  ");
       if(ps2x.Button(PSB_PAD_UP))             /* will be TRUE as long as UP button is pressed */       if(ps2x.Button(PSB_PAD_UP))             /* will be TRUE as long as UP button is pressed */
-         lcd.print("UP PRESSED      "); +         Serial.println("UP PRESSED      "); 
       if(ps2x.Button(PSB_PAD_RIGHT))          /* will be TRUE as long as UP button is pressed */       if(ps2x.Button(PSB_PAD_RIGHT))          /* will be TRUE as long as UP button is pressed */
-         lcd.print("RIGHT PRESSED   ");+         Serial.println("RIGHT PRESSED   ");
       if(ps2x.Button(PSB_PAD_LEFT))           /* will be TRUE as long as LEFT button is pressed */       if(ps2x.Button(PSB_PAD_LEFT))           /* will be TRUE as long as LEFT button is pressed */
-         lcd.print("LEFT PRESSED    "); +         Serial.println("LEFT PRESSED    "); 
       if(ps2x.Button(PSB_PAD_DOWN))           /* will be TRUE as long as DOWN button is pressed */       if(ps2x.Button(PSB_PAD_DOWN))           /* will be TRUE as long as DOWN button is pressed */
-         lcd.print("DOWN PRESSED    "); +         Serial.println("DOWN PRESSED    "); 
       if(ps2x.Button(PSB_L1))                 /* will be TRUE as long as L1 button is pressed */       if(ps2x.Button(PSB_L1))                 /* will be TRUE as long as L1 button is pressed */
-         lcd.print("L1 pressed      ");+         Serial.println("L1 pressed      ");
       if(ps2x.Button(PSB_R1))                 /* will be TRUE as long as R1 button is pressed */       if(ps2x.Button(PSB_R1))                 /* will be TRUE as long as R1 button is pressed */
-         lcd.print("R1 pressed      "); +         Serial.println("R1 pressed      "); 
       if(ps2x.Button(PSB_L2))                 /* will be TRUE as long as L2 button is pressed */       if(ps2x.Button(PSB_L2))                 /* will be TRUE as long as L2 button is pressed */
-         lcd.print("L2 pressed      ");+         Serial.println("L2 pressed      ");
       if(ps2x.Button(PSB_R2))                 /* will be TRUE as long as R2 button is pressed */       if(ps2x.Button(PSB_R2))                 /* will be TRUE as long as R2 button is pressed */
-         lcd.print("R2 pressed      ");+         Serial.println("R2 pressed      ");
       if(ps2x.Button(PSB_L3))                 /* will be TRUE as long as L3 button is pressed */       if(ps2x.Button(PSB_L3))                 /* will be TRUE as long as L3 button is pressed */
-         lcd.print("L3 pressed      ");+         Serial.println("L3 pressed      ");
       if(ps2x.Button(PSB_R3))                 /* will be TRUE as long as R3 button is pressed */       if(ps2x.Button(PSB_R3))                 /* will be TRUE as long as R3 button is pressed */
-         lcd.print("R3 pressed      ");+         Serial.println("R3 pressed      ");
       if(ps2x.Button(PSB_GREEN))              /* will be TRUE as long as GREEN/Triangle button is pressed */       if(ps2x.Button(PSB_GREEN))              /* will be TRUE as long as GREEN/Triangle button is pressed */
-         lcd.print("Triangle pressed");+         Serial.println("Triangle pressed");
       if(ps2x.Button(PSB_BLUE))                /* will be TRUE as long as BLUE/CROSS/X button is pressed */       if(ps2x.Button(PSB_BLUE))                /* will be TRUE as long as BLUE/CROSS/X button is pressed */
-         lcd.print("X pressed       "); +         Serial.println("X pressed       "); 
        if(ps2x.Button(PSB_RED))               /* will be TRUE as long as RED/Circle button is pressed */        if(ps2x.Button(PSB_RED))               /* will be TRUE as long as RED/Circle button is pressed */
-         lcd.print("Circle pressed  "); +         Serial.println("Circle pressed  "); 
       if(ps2x.Button(PSB_PINK))               /* will be TRUE as long as PINK/Squre button is pressed */       if(ps2x.Button(PSB_PINK))               /* will be TRUE as long as PINK/Squre button is pressed */
-         lcd.print("Square pressed  "); +         Serial.println("Square pressed  "); 
       delay(700);       delay(700);
    }    }
Ligne 133: Ligne 134:
  
 </code> </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.1652108690.txt.gz · Dernière modification : 2023/01/27 16:08 (modification externe)