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 :

Choix du fichier mp3 avec un shield vs1053b


Sujet :

Arduino

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Candidat au Club
    Homme Profil pro
    Technicien maintenance
    Inscrit en
    Octobre 2021
    Messages
    2
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 56
    Localisation : France, Bas Rhin (Alsace)

    Informations professionnelles :
    Activité : Technicien maintenance
    Secteur : Alimentation

    Informations forums :
    Inscription : Octobre 2021
    Messages : 2
    Par défaut Choix du fichier mp3 avec un shield vs1053b
    voilà, je travail sur un projet pour une association.
    je me sert d'un uno et d'un shield mp3 vs1053, j'ai un programme qui fonctionne mais pas tout à fait comme je voudrai.
    je peux choisir 9 fichier mp3 en mettant le entrée à la masse, ca fonctionne et mon problème c'est que quand je choisi la piste 1 par example, et bien lorsqu'elle est fini, je ne peux pas la rejouer sans avoir activé un autre fichier. et je ne veux pas me servir de A5
    j'ai essayé plein de chose, je débute
    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
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    /*
     
      MP3 Shield Trigger
     
      by: Jim Lindblom
     
          SparkFun Electronics
     
      date: September 23, 2013
     
     
      This is an example MP3 trigger sketch for the SparkFun MP3 Shield.
     
      Pins 0, 1, 5, 10, A0, A1, A2, A3, and A4 are setup to trigger tracks
     
      "track001.mp3", "track002.mp3", etc. on an SD card loaded into
     
      the shield. Whenever any of those pins are shorted to ground,
     
      their respective track will start playing.
     
     
      When a new pin is triggered, any track currently playing will
     
      stop, and the new one will start.
     
     
      A5 is setup to globally STOP playing a track when triggered.
     
     
      If you need more triggers, the shield's jumpers on pins 3 and 4
     
      (MIDI-IN and GPIO1) can be cut open and used as additional
     
      trigger pins. Also, because pins 0 and 1 are used as triggers
     
      Serial is not available for debugging. Disable those as
     
      triggers if you want to use serial.
     
     
      Much of this code was grabbed from the FilePlayer example
     
      included with the SFEMP3Shield library. Major thanks to Bill
     
      Porter and Michael Flaga, again, for this amazing library!
     
    */
     
     
    #include <SPI.h>           // SPI library
     
    #include <SdFat.h>         // SDFat Library
     
    #include <SdFatUtil.h>     // SDFat Util Library
     
    #include <SFEMP3Shield.h>  // Mp3 Shield Library
     
     
    SdFat sd; // Create object to handle SD functions
     
     
    SFEMP3Shield MP3player; // Create Mp3 library object
     
    // These variables are used in the MP3 initialization to set up
     
    // some stereo options:
     
    const uint8_t volume = 0; // MP3 Player volume 0=max, 255=lowest (off)
     
    const uint16_t monoMode = 1;  // Mono setting 0=off, 3=max
     
     
    /* Pin setup */
     
    #define TRIGGER_COUNT 9
     
    int triggerPins[TRIGGER_COUNT] = {0, 1, 5, 10, A0, A1, A2, A3, A4};
     
    int stopPin = A5; // This pin triggers a track stop.
     
    int lastTrigger = 0; // This variable keeps track of which tune is playing
     
     
    void setup()
     
    {
     
      /* Set up all trigger pins as inputs, with pull-ups activated: */
     
      for (int i=0; i<TRIGGER_COUNT; i++)
     
      {
     
        pinMode(triggerPins[i], INPUT_PULLUP);
     
      }
     
      pinMode(stopPin, INPUT_PULLUP);
     
     
      initSD();  // Initialize the SD card
     
      initMP3Player(); // Initialize the MP3 Shield
     
    }
     
     
    // All the loop does is continuously step through the trigger
     
    //  pins to see if one is pulled low. If it is, it'll stop any
     
    //  currently playing track, and start playing a new one.
     
    void loop()
     
    {
     
      for (int i=0; i<TRIGGER_COUNT; i++)
     
      {
     
        if ((digitalRead(triggerPins[i]) == LOW) && ((i+1) != lastTrigger))
     
        {
     
          lastTrigger = i+1; // Update lastTrigger variable to current trigger
     
          /* If another track is playing, stop it: */
     
          if (MP3player.isPlaying())
     
            MP3player.stopTrack();
     
     
          /* Use the playTrack function to play a numbered track: */
     
          uint8_t result = MP3player.playTrack(lastTrigger);
     
          // An alternative here would be to use the
     
          //  playMP3(fileName) function, as long as you mapped
     
          //  the file names to trigger pins.
     
     
          if (result == 0)  // playTrack() returns 0 on success
     
          {
     
            // Success
     
          }
     
          else // Otherwise there's an error, check the code
     
          {
     
            // Print error code somehow, someway
     
          }
     
        }
     
      }
     
      // After looping through and checking trigger pins, check to
     
      //  see if the stopPin (A5) is triggered.
     
      if (digitalRead(stopPin)  == LOW)
     
      {
     
        lastTrigger = 0; // Reset lastTrigger
     
        // If another track is playing, stop it.
     
        if (MP3player.isPlaying())
     
          MP3player.stopTrack();
     
      }
     
    }
     
     
    // initSD() initializes the SD card and checks for an error.
     
    void initSD()
     
    {
     
      //Initialize the SdCard.
     
      if(!sd.begin(SD_SEL, SPI_HALF_SPEED))
     
        sd.initErrorHalt();
     
      if(!sd.chdir("/"))
     
        sd.errorHalt("sd.chdir");
     
    }
     
     
    // initMP3Player() sets up all of the initialization for the
     
    // MP3 Player Shield. It runs the begin() function, checks
     
    // for errors, applies a patch if found, and sets the volume/
     
    // stero mode.
     
    void initMP3Player()
     
    {
     
      uint8_t result = MP3player.begin(); // init the mp3 player shield
     
      if(result != 0) // check result, see readme for error codes.
     
      {
     
        // Error checking can go here!
     
      }
     
      MP3player.setVolume(volume, volume);
     
      MP3player.setMonoMode(monoMode);
     
    }

  2. #2
    Expert confirmé

    Homme Profil pro
    mad scientist :)
    Inscrit en
    Septembre 2019
    Messages
    2 908
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Etats-Unis

    Informations professionnelles :
    Activité : mad scientist :)

    Informations forums :
    Inscription : Septembre 2019
    Messages : 2 908
    Par défaut
    Avec ce code dans le test

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    && ((i+1) != lastTrigger))
    Vous vous empêchez se jouer deux fois de suite la même piste. Il faudrait détecter la fin se piste et remettre lastTrigger à 0 à ce moment là

  3. #3
    Candidat au Club
    Homme Profil pro
    Technicien maintenance
    Inscrit en
    Octobre 2021
    Messages
    2
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 56
    Localisation : France, Bas Rhin (Alsace)

    Informations professionnelles :
    Activité : Technicien maintenance
    Secteur : Alimentation

    Informations forums :
    Inscription : Octobre 2021
    Messages : 2
    Par défaut
    je vous remercie pour votre aide, cela fonctionne, mais juste la sortie 1 ne fonctionne pas du coup.
    Mais c'est pas grave je ne me sert pas de cette sortie et prend les autre. merci de votre aide

Discussions similaires

  1. ouvrir un fichier mp3 avec openfilname et le jouer avec fmod
    Par levasseur62 dans le forum Débuter
    Réponses: 6
    Dernier message: 15/08/2011, 23h19
  2. Lecture de fichier mp3 avec servlets/JSP
    Par MarENSI dans le forum Servlets/JSP
    Réponses: 2
    Dernier message: 29/10/2010, 14h38
  3. Lire un fichier mp3 avec Java
    Par hebmaster dans le forum Multimédia
    Réponses: 2
    Dernier message: 18/05/2007, 18h53
  4. Utiliser un fichier MP3 avec Java
    Par musicg dans le forum Multimédia
    Réponses: 3
    Dernier message: 27/09/2006, 16h56
  5. importer des fichiers mp3 avec sql server uniquement
    Par cool dans le forum MS SQL Server
    Réponses: 1
    Dernier message: 08/04/2006, 13h21

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