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

Langage C++ Discussion :

Array of Char array


Sujet :

Langage C++

  1. #1
    Nouveau Candidat au Club
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Avril 2016
    Messages
    2
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : Suisse

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : Arts - Culture

    Informations forums :
    Inscription : Avril 2016
    Messages : 2
    Points : 1
    Points
    1
    Par défaut Array of Char array
    Bonjour,

    Je sèche sur un problème Arduino et je ne sais pas comment/où trouver une solution.
    J'ai une liste de variables que j'aimerais mettre dans un tableau de manière à pouvoir choisir aléatoirement un des éléments du tableau.

    Comment créer un tableau avec ces valeurs et comment passer un élément du tableau à la fonction?

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
     
    //char *song = "Bond:d=4,o=5,b=80:32p,16c#6,32d#6,32d#6,16d#6,8d#6,16c#6,16c#6,16c#6,16c#6,32e6,32e6,16e6,8e6,16d#6,16d#6,16d#6,16c#6,32d#6,32d#6,16d#6,8d#6,16c#6,16c#6,16c#6,16c#6,32e6,32e6,16e6,8e6,16d#6,16d6,16c#6,16c#7,c.7,16g#6,16f#6,g#.6";
    //char *song = "MASH:d=8,o=5,b=140:4a,4g,f#,g,p,f#,p,g,p,f#,p,2e.,p,f#,e,4f#,e,f#,p,e,p,4d.,p,f#,4e,d,e,p,d,p,e,p,d,p,2c#.,p,d,c#,4d,c#,d,p,e,p,4f#,p,a,p,4b,a,b,p,a,p,b,p,2a.,4p,a,b,a,4b,a,b,p,2a.,a,4f#,a,b,p,d6,p,4e.6,d6,b,p,a,p,2b";
    //char *song = "StarWars:d=4,o=5,b=45:32p,32f#,32f#,32f#,8b.,8f#.6,32e6,32d#6,32c#6,8b.6,16f#.6,32e6,32d#6,32c#6,8b.6,16f#.6,32e6,32d#6,32e6,8c#.6,32f#,32f#,32f#,8b.,8f#.6,32e6,32d#6,32c#6,8b.6,16f#.6,32e6,32d#6,32c#6,8b.6,16f#.6,32e6,32d#6,32e6,8c#6";
    //char *song = "GoodBad:d=4,o=5,b=56:32p,32a#,32d#6,32a#,32d#6,8a#.,16f#.,16g#.,d#,32a#,32d#6,32a#,32d#6,8a#.,16f#.,16g#.,c#6,32a#,32d#6,32a#,32d#6,8a#.,16f#.,32f.,32d#.,c#,32a#,32d#6,32a#,32d#6,8a#.,16g#.,d#";
    //char *song = "TopGun:d=4,o=4,b=31:32p,16c#,16g#,16g#,32f#,32f,32f#,32f,16d#,16d#,32c#,32d#,16f,32d#,32f,16f#,32f,32c#,16f,d#,16c#,16g#,16g#,32f#,32f,32f#,32f,16d#,16d#,32c#,32d#,16f,32d#,32f,16f#,32f,32c#,g#";
    char *song = "A-Team:d=8,o=5,b=125:4d#6,a#,2d#6,16p,g#,4a#,4d#.,p,16g,16a#,d#6,a#,f6,2d#6,16p,c#.6,16c6,16a#,g#.,2a#";
    Appel de la fonction:
    Fonction:
    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
    void play_rtttl(char *p)
    {
    	// Absolutely no error checking in here
     
    	byte default_dur = 4;
    	byte default_oct = 6;
    	int bpm = 63;
    	int num;
    	long wholenote;
    	long duration;
    	byte note;
    	byte scale;
     
    	// format: d=N,o=N,b=NNN:
    	// find the start (skip name, etc)
     
    	while (*p != ':') p++;    // ignore name
    	p++;                     // skip ':'
     
    	// get default duration
    	if (*p == 'd')
    	{
    		p++; p++;              // skip "d="
    		num = 0;
    		while (isdigit(*p))
    		{
    			num = (num * 10) + (*p++ - '0');
    		}
    		if (num > 0) default_dur = num;
    		p++;                   // skip comma
    	}
     
    	Serial.print("ddur: "); Serial.println(default_dur, 10);
     
    	// get default octave
    	if (*p == 'o')
    	{
    		p++; p++;              // skip "o="
    		num = *p++ - '0';
    		if (num >= 3 && num <= 7) default_oct = num;
    		p++;                   // skip comma
    	}
     
    	Serial.print("doct: "); Serial.println(default_oct, 10);
     
    	// get BPM
    	if (*p == 'b')
    	{
    		p++; p++;              // skip "b="
    		num = 0;
    		while (isdigit(*p))
    		{
    			num = (num * 10) + (*p++ - '0');
    		}
    		bpm = num;
    		p++;                   // skip colon
    	}
     
    	Serial.print("bpm: "); Serial.println(bpm, 10);
     
    	// BPM usually expresses the number of quarter notes per minute
    	wholenote = (60 * 1000L / bpm) * 4;  // this is the time for whole note (in milliseconds)
     
    	Serial.print("wn: "); Serial.println(wholenote, 10);
     
     
    	// now begin note loop
    	while (*p)
    	{
    		// first, get note duration, if available
    		num = 0;
    		while (isdigit(*p))
    		{
    			num = (num * 10) + (*p++ - '0');
    		}
     
    		if (num) duration = wholenote / num;
    		else duration = wholenote / default_dur;  // we will need to check if we are a dotted note after
     
    		// now get the note
    		note = 0;
     
    		switch (*p)
    		{
    		case 'c':
    			note = 1;
    			break;
    		case 'd':
    			note = 3;
    			break;
    		case 'e':
    			note = 5;
    			break;
    		case 'f':
    			note = 6;
    			break;
    		case 'g':
    			note = 8;
    			break;
    		case 'a':
    			note = 10;
    			break;
    		case 'b':
    			note = 12;
    			break;
    		case 'p':
    		default:
    			note = 0;
    		}
    		p++;
     
    		// now, get optional '#' sharp
    		if (*p == '#')
    		{
    			note++;
    			p++;
    		}
     
    		// now, get optional '.' dotted note
    		if (*p == '.')
    		{
    			duration += duration / 2;
    			p++;
    		}
     
    		// now, get scale
    		if (isdigit(*p))
    		{
    			scale = *p - '0';
    			p++;
    		}
    		else
    		{
    			scale = default_oct;
    		}
     
    		scale += OCTAVE_OFFSET;
     
    		if (*p == ',')
    			p++;       // skip comma for next note (or we may be at the end)
     
    		  // now play the note
     
    		if (note)
    		{
    			Serial.print("Playing: ");
    			Serial.print(scale, 10); Serial.print(' ');
    			Serial.print(note, 10); Serial.print(" (");
    			Serial.print(notes[(scale - 4) * 12 + note], 10);
    			Serial.print(") ");
    			Serial.println(duration, 10);
    			tone1.play(notes[(scale - 4) * 12 + note]);
    			delay(duration);
    			tone1.stop();
    		}
    		else
    		{
    			Serial.print("Pausing: ");
    			Serial.println(duration, 10);
    			delay(duration);
    		}
    	}
    }

  2. #2
    Rédacteur/Modérateur


    Homme Profil pro
    Network game programmer
    Inscrit en
    Juin 2010
    Messages
    7 113
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : Canada

    Informations professionnelles :
    Activité : Network game programmer

    Informations forums :
    Inscription : Juin 2010
    Messages : 7 113
    Points : 32 958
    Points
    32 958
    Billets dans le blog
    4
    Par défaut
    Euh tu veux dire que tu ne trouves pas la syntaxe
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    char* songs[] = {"...", "....", "...", ...};
    Ou c'est le random que tu ne sais pas faire ?
    Ou c'est le passage de paramètre ?

    Dans tous les cas ça ressemble à un problème de syntaxe et donc de base du langage, et non d'Arduino.
    Pensez à consulter la FAQ ou les cours et tutoriels de la section C++.
    Un peu de programmation réseau ?
    Aucune aide via MP ne sera dispensée. Merci d'utiliser les forums prévus à cet effet.

  3. #3
    Nouveau Candidat au Club
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Avril 2016
    Messages
    2
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : Suisse

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : Arts - Culture

    Informations forums :
    Inscription : Avril 2016
    Messages : 2
    Points : 1
    Points
    1
    Par défaut
    Hello,

    Merci pour la réponse!

    La question était: Comment créer un tableau avec ces valeurs et comment passer un élément du tableau à la fonction?

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Spliter un string en array of char ?
    Par MaTHieU_ dans le forum Delphi
    Réponses: 5
    Dernier message: 18/03/2007, 23h11
  2. Copy String to array of char
    Par Ardely dans le forum Delphi
    Réponses: 11
    Dernier message: 11/02/2007, 01h24
  3. Champ String et Constante Array of Char ?
    Par BXDSPORT dans le forum Delphi
    Réponses: 4
    Dernier message: 24/08/2006, 13h35
  4. Array subscript has type 'char'
    Par obelix dans le forum C
    Réponses: 11
    Dernier message: 31/10/2005, 19h21
  5. TFileStream et Array of char
    Par busy999 dans le forum Langage
    Réponses: 2
    Dernier message: 06/07/2004, 22h00

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