IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Arduino Discussion :

pro micro et controleur de jeu


Sujet :

Arduino

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Homme Profil pro
    pompier
    Inscrit en
    Janvier 2020
    Messages
    86
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 50
    Localisation : France, Eure et Loir (Centre)

    Informations professionnelles :
    Activité : pompier

    Informations forums :
    Inscription : Janvier 2020
    Messages : 86
    Par défaut pro micro et controleur de jeu
    bonjour à tous,

    j'ai donc une carte arduino pro micro avec un potentiomètre en A0.

    je rentre le code suivant

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    // Program used to test the USB Joystick library when used as 
    // a Flight Controller on the Arduino Leonardo or Arduino 
    // Micro.
    //
    // Matthew Heironimus
    // 2016-05-29 - Original Version
    //------------------------------------------------------------
     
    #include "Joystick.h"
     
    Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID, 
      JOYSTICK_TYPE_MULTI_AXIS, 32, 0,
      true, true, false, false, false, false,
      true, true, false, false, false);
     
    // Set to true to test "Auto Send" mode or false to test "Manual Send" mode.
    //const bool testAutoSendMode = true;
    const bool testAutoSendMode = false;
     
    const unsigned long gcCycleDelta = 1000;
    const unsigned long gcAnalogDelta = 25;
    const unsigned long gcButtonDelta = 500;
    unsigned long gNextTime = 0;
    unsigned int gCurrentStep = 0;
     
    void testSingleButtonPush(unsigned int button)
    {
      if (button > 0)
      {
        Joystick.releaseButton(button - 1);
      }
      if (button < 32)
      {
        Joystick.pressButton(button);
      }
    }
     
    void testMultiButtonPush(unsigned int currentStep) 
    {
      for (int button = 0; button < 32; button++)
      {
        if ((currentStep == 0) || (currentStep == 2))
        {
          if ((button % 2) == 0)
          {
            Joystick.pressButton(button);
          } else if (currentStep != 2)
          {
            Joystick.releaseButton(button);
          }
        } // if ((currentStep == 0) || (currentStep == 2))
        if ((currentStep == 1) || (currentStep == 2))
        {
          if ((button % 2) != 0)
          {
            Joystick.pressButton(button);
          } else if (currentStep != 2)
          {
            Joystick.releaseButton(button);
          }
        } // if ((currentStep == 1) || (currentStep == 2))
        if (currentStep == 3)
        {
          Joystick.releaseButton(button);
        } // if (currentStep == 3)
      } // for (int button = 0; button < 32; button++)
    }
     
    void testXYAxis(unsigned int currentStep)
    {
      int xAxis;
      int yAxis;
     
      if (currentStep < 256)
      {
        xAxis = currentStep - 127;
        yAxis = -127;
        Joystick.setXAxis(xAxis);
        Joystick.setYAxis(yAxis);
      } 
      else if (currentStep < 512)
      {
        yAxis = currentStep - 256 - 127;
        Joystick.setYAxis(yAxis);
      }
      else if (currentStep < 768)
      {
        xAxis = 128 - (currentStep - 512);
        Joystick.setXAxis(xAxis);
      }
      else if (currentStep < 1024)
      {
        yAxis = 128 - (currentStep - 768);
        Joystick.setYAxis(yAxis);
      }
      else if (currentStep < 1024 + 128)
      {
        xAxis = currentStep - 1024 - 127;
        Joystick.setXAxis(xAxis);
        Joystick.setYAxis(xAxis);
      }
    }
     
    void testThrottleRudder(unsigned int value)
    {
      Joystick.setThrottle(value);
      Joystick.setRudder(255 - value);
    }
     
    void setup() {
     
      Joystick.setXAxisRange(-127, 127);
      Joystick.setYAxisRange(-127, 127);
      Joystick.setZAxisRange(-127, 127);
      Joystick.setThrottleRange(0, 255);
      Joystick.setRudderRange(0, 255);
     
      if (testAutoSendMode)
      {
        Joystick.begin();
      }
      else
      {
        Joystick.begin(false);
      }
     
      pinMode(A0, INPUT_PULLUP);
      pinMode(LED_BUILTIN, OUTPUT);
    }
     
    void loop() {
     
      // System Disabled
      if (digitalRead(A0) != 0)
      {
        // Turn indicator light off.
        digitalWrite(LED_BUILTIN, 0);
        return;
      }
     
      // Turn indicator light on.
      digitalWrite(LED_BUILTIN, 1);
     
      if (millis() >= gNextTime)
      {
     
        if (gCurrentStep < 33)
        {
          gNextTime = millis() + gcButtonDelta;
          testSingleButtonPush(gCurrentStep);
        } 
        else if (gCurrentStep < 37)
        {
          gNextTime = millis() + gcButtonDelta;
          testMultiButtonPush(gCurrentStep - 33);
        }
        else if (gCurrentStep < (37 + 256))
        {
          gNextTime = millis() + gcAnalogDelta;
          testThrottleRudder(gCurrentStep - 37);
        }
        else if (gCurrentStep < (37 + 256 + 1024 + 128))
        {
          gNextTime = millis() + gcAnalogDelta;
          testXYAxis(gCurrentStep - (37 + 256));
        }
     
        if (testAutoSendMode == false)
        {
          Joystick.sendState();
        }
     
        gCurrentStep++;
        if (gCurrentStep >= (37 + 256 + 1024 + 128))
        {
          gNextTime = millis() + gcCycleDelta;
          gCurrentStep = 0;
        }
      }
    }
    Quand le potentiomètre n'est pas à la position maximale rien ne se passe dans le contrôleur de jeu.
    Quand il est à sa position maximal, c'est un vrai sapin de noël. Les boutons clignotent les uns après les autres.

    Auriez vous une idées?
    En fait je ne veux pour le moment que récupérer la valeur de la commande des gaz
    J'ai vu que la broche A0 équivaut à la broche 18
    Merci par avance pour votre retour et belles fêtes de fin d'année.

  2. #2
    Responsable Arduino et Systèmes Embarqués


    Avatar de f-leb
    Homme Profil pro
    Enseignant
    Inscrit en
    Janvier 2009
    Messages
    13 200
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 54
    Localisation : France, Sarthe (Pays de la Loire)

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Janvier 2009
    Messages : 13 200
    Billets dans le blog
    47
    Par défaut
    Bonsoir,

    Il s'agit bien d'un potentiomètre analogique en A0 ?

    Parce que tu as déclaré A0 comme entrée (avec pull-up) :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    pinMode(A0, INPUT_PULLUP);
    et tu lis A0 comme une entrée numérique avec digitalRead(A0).

    Dès lors, l'entrée ne peut prendre que deux états, et je ne vois rien d'étonnant à ce que soit il ne se passe rien, soit tout s'allume...

Discussions similaires

  1. Arduino micro - contrôleur de jeu USB
    Par hugobeauce dans le forum Arduino
    Réponses: 5
    Dernier message: 25/05/2024, 17h52
  2. Réponses: 5
    Dernier message: 13/05/2014, 15h54
  3. Réponses: 12
    Dernier message: 17/04/2014, 09h56
  4. Information étalonnage controleurs de jeu
    Par check_acr dans le forum Windows XP
    Réponses: 0
    Dernier message: 04/11/2010, 10h24
  5. [XP Pro] Micro Hs
    Par J_Lennon dans le forum Windows XP
    Réponses: 3
    Dernier message: 22/10/2009, 21h43

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo