Stap 4: Uploaden van de Code
1. Controleer alle aansluitingen.
a) van het bord aan de spreker.
b) USB-aansluiting van het bord op de computer.
2. open de Arduino Software (met de Arduino board aangesloten op de computer)
3. Ga door naar de volgende code uploaden: (er zijn verschillende tones(songs) op de code Kopieer en plak het in de juiste lijn).
CODE:
Een leuke sketch om aan te tonen het gebruik van de Tone library.
#include < Tone.h >
Toon tone1;
#define OCTAVE_OFFSET 0
int merkt [] = {0,
NOTE_C4, NOTE_CS4, NOTE_D4, NOTE_DS4, NOTE_E4, NOTE_F4, NOTE_FS4, NOTE_G4, NOTE_GS4, NOTE_A4, NOTE_AS4, NOTE_B4,
NOTE_C5, NOTE_CS5, NOTE_D5, NOTE_DS5, NOTE_E5, NOTE_F5, NOTE_FS5, NOTE_G5, NOTE_GS5, NOTE_A5, NOTE_AS5, NOTE_B5,
NOTE_C6, NOTE_CS6, NOTE_D6, NOTE_DS6, NOTE_E6, NOTE_F6, NOTE_FS6, NOTE_G6, NOTE_GS6, NOTE_A6, NOTE_AS6, NOTE_B6,
NOTE_C7, NOTE_CS7, NOTE_D7, NOTE_DS7, NOTE_E7, NOTE_F7, NOTE_FS7, NOTE_G7, NOTE_GS7, NOTE_A7, NOTE_AS7, NOTE_B7
};
char * nummer = "The Simpsons:d=4,o=5,b=160:c.6,e6,f#6,8a6,g.6,e6,c6,8a,8f#,8f#,8f#,2g,8p,8p,8f#,8f#,8f#,8g,a#.,8c6,8c6,8c6,c6";
char * nummer = "Indiana: d = 4, o = 5, b = 250:e 8 p, 8f, 8 g, 8 p, 1 c, 6, 8 p., d, 8 p, 8e, 1f, p., g, 8 p, 8a, 8b, 8 p, 1f6, p, a, 8 p, 8b, 2 c 6, 2 d 6, 2e6, e, 8 p, 8f, 8 g, 8 p, 1 c 6, p, d6, 8 p, 8e6, 1f.6, g, 8 p, 8 g, e.6, 8 p, d6, 8 p, 8 g, e.6, 8 p, d6, 8 p, 8 g, f.6, 8 p, e6 , 8p, 8d 6, 2c 6";
char *song = "TakeOnMe:d=4,o=4,b=160:8f#5,8f#5,8f#5,8d5,8p,8b,8p,8e5,8p,8e5,8p,8e5,8g#5,8g#5,8a5,8b5,8a5,8a5,8a5,8e5,8p,8d5,8p,8f#5,8p,8f#5,8p,8f#5,8e5,8e5,8f#5,8e5,8f#5,8f#5,8f#5,8d5,8p,8b,8p,8e5,8p,8e5,8p,8e5,8g#5,8g#5,8a5,8b5,8a5,8a5,8a5,8e5,8p , 8d 5, 8p, 8f #5, 8p, 8f #5, 8p, 8f #5, 8e5, 8e5 ";
char * nummer = "Entertainer:d=4,o=5,b=140:8d,8d#,8e,c6,8e,c6,8e,2c.6,8c6,8d6,8d#6,8e6,8c6,8d6,e6,8b,d6,2c6,p,8d,8d#,8e,c6,8e,c6,8e,2c.6,8p,8a,8g,8f#,8a,8c6,e6,8d6,8c6,8a,2d6";
char * nummer = "Muppets:d = 4, o = 5, b = 250:c6, c6, a, b, 8a, b, g, p, c6, c6, a, 8b, 8a, 8 p, g., p, e, e, g, f, 8e, f, 8 c, 6, 8 c, 8 d, e, 8e, 8e, 8 p, 8e, g, 2 p, c6, c6, a, b, 8a, b, g, p, c6, c6, a, 8b, a, g., p e, e, g, f, 8e f, 8 c, 6, 8 c, 8 d, e, 8e, d, 8 d, c ";
char * nummer = "Xfiles:d = 4, o = 5, b = 125:e, b, a, b, d6, 2b., 1 p, e, b, a, b, e6, 2b., 1 p, g6, f #6, e6, d6, e6, 2b., 1 p, g6, f #6, e6, d6, f #6, 2b., 1 p, e, b, a, b, d6, 2b., 1 p, e, b, a, b, e6, 2b, 1 p, e6, 2b.";
char * nummer = "Looney: d = 4, o = 5, b = 140:32 p, c6, 8f6, 8e6, 8 d 6, 8 c, 6, a., 8 c, 6, 8f6, 8e6, 8 d 6, 8 d #6,e.6,8e6,8e6,8c6,8d6,8c6,8e6,8c6,8d6,8a,8c6,8g,8a #, 8a, 8f";
char * nummer = "20thCenFox:d = 16, o = 5, b = 140:b, 8 p, b, b, 2b, p, c6, 32 p, b, 32 p, c6, 32 p, b, 32 p, c6, 32 p, b, 8 p, b, b, b, 32 p, b, 32 p, b, 32 p, b, 32 p, b, 32 p, b, 32 p, b, 32 p, g #, 32 p, a, 32 p, b, 8 p, b, b, 2b, 4 p, 8e, 8 g #, 8b, 1 c# 6, 8f #, 8a, 8 c# 6, 1e6 8a, 8 c# 6, 8e6, 1e6, 8b, 8 g #, 8a, 2b ";
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 * nummer = "MASH:d = 8, o = 5, b = 140:4a, 4 g, f #, g, p, f #, p, g, p, f #, p, 2e., p, f #, e, 4f #, e, f #, p, e, p, 4 d., p f #, 4e, d, e, p, o, p, e, p, o, p, 2 c#., p, d, c#, 4 d, c#, d, p, e, p, 4f #, p, a, p, 4b, a, b, p, een p b, p, 2a., 4 p, 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 * nummer = "GoodBad:d = 4, o = 5, b = 56:32 p, 32a #, 32ste #6, 32a #, 32ste #6, 8a #., 16 septies #., 16 g #., d #, 32a #, 32ste #6, 32a #, 32ste #6, 8a #., 16 septies #., 16 g #., c# 6, 32a #, 32ste #6, 32a #, 32ste #6, 8a #., 16 septies #., 32f., 32ste #, c#, 32a #, 32ste #6, 32a #, 32ste #6, 8a #., 16 g #., d #";
char * nummer = "TopGun:d = 4, o = 4, b = 31:32 p 16 c#, 16 g #, g # 16, 32f #, 32f, 32f #, 32f, 16 d #, 16 d #, 32 c#, 32ste #, 16 septies, 32ste #, 32f, 16 septies #, 32f, 32 c#, 16 septies, d #, 16 c#, 16 g #, g # 16, 32f #, 32f, 32f #, 32f, 16 d #, 16 d #, 32 c#, 32ste # 16 septies, 32ste #, 32f, 16 septies #, 32f, 32 c#, g #";
char * nummer = "A-Team: d = 8, o = 5, b = 125:4 d #6, een #, 2d #6, 16 p g #, 4a #, 4 d #., p, 16 g, 16a #, d #6, een #, f6, 2d #6, 16 p c#.6, 16 c 6, 16a #, g #., 2a #";
char *song = "Flinstones:d=4,o=5,b=40:32p,16f6,16a#,16a#6,32g6,16f6,16a#.,16f6,32d#6,32d6,32d6,32d#6,32f6,16a#,16c6,d6,16f6,16a#.,16a#6,32g6,16f6,16a#.,32f6,32f6,32d#6,32d6,32d6,32d#6,32f6,16a#,16c6,a#,16a6,16d.6,16a#6,32a6,32a6,32g6,32f#6,32a6,8g6,16g6,16c.6,32a6,32a6,32g6,32g6,32f6,32e6,32g6,8f6,16f6,16a#. , 16a #6, 32g 6, 16f6, 16a #., 16f6, 32ste #6, 32d 6, 32d 6, 32ste #6, 32f6, 16a #, 16c.6,32d6, 32ste #6, 32f6, 16a #, 16c.6,32d6, 32ste #6, 32f6, 16a #6, 16c 7, 8a #.6";
char * nummer = "gevaar: d = 4, o = 6, b = 125:c, f, c, f5, c, f, 2 c, c, f, c, f, a., 8 g, 8f, 8e, 8 d, 8 c#, c, f, c, f5, c, f, 2 c, f., 8 d, c, een #5, a5, g5, f5, p, d #, g #, d #, g #5, d #, g #, 2d #, d #, g #, d #, g #, c.7, 8a #, g # 8, 8 g, 8f, 8e, d # , g # d #, g #5, d #, g #, 2d #, g #., 8f, d #, c#, c, p, een #5, p, g #.5, d #, g #";"
char * nummer = "Gadget: d = 16, o = 5, b = 50:32d # 32f, 32f #, 32 g #, #, f #, a, f, g #, f #, 32ste #, 32f, 32f #, 32 g #, #, d #6, 4 d 6, 32ste # 32f, 32f #, 32 g #, #, f #, a, f, g #, f #, 8 d #";
char * nummer = "Smurfs:d = 32, o = 5, b = 200:4 c# 6, 16 p, 4f #6, p, 16 c# 6, p, 8 d #6, p, 8b, p, 4 g #, 16 p, 4 c# 6, p, 16a #, p, 8f #, p, 8a #, p, 4 g #, 4 p, g #, p, een #, p, b, p, c6, p, 4 c# 6, 16 p, 4f #6, p, 16 c# 6 p, 8 d #6, p, 8b, p, 4 g #, 16 p, 4 c# 6, p, 16a # , p, 8b, p, 8f, p, 4f #";"
char * nummer = "MahnaMahna:d = 16, o = 6, b = 125:c#, c., b5, 8a #.5, 8f. 4 g #, #, g., 4 d #, 8 p, c#, c, b5, 8a #.5, 8f., g #., 8a #., 4 g, 8 p, c#, c, b5, 8a #.5, 8f. 4 g #, f, g., 8 d #., f, g., 8 d #., f, 8 g, 8 d #., f 8 g, d #, 8 c, een #5, 8 d #., 8 d #., 4 d #, 8 d #.";
char * nummer = "LeisureSuit:d=16,o=6,b=56:f.5,f#.5,g.5,g#5,32a#5,f5,g#.5,a#.5,32f5,g#5,32a#5,g#5,8c#.,a#5,32c#,a5,a#.5,c#.,32a5,a#5,32c#,d#,8e,c#.,f.,f.,f.,f.,f,32e,d#,8d,a#.5,e,32f,e,32f,c#,d#.,c#";
char *song = "smb:d=4,o=5,b=100:16e6,16e6,32p,8e6,16c6,8e6,8g6,8p,8g,8p,8c6,16p,8g,16p,8e,16p,8a,8b,16a#,8a,16g.,16e6,16g6,8a6,16f6,8g6,8e6,16c6,16d6,8b,16p,8c6,16p,8g,16p,8e,16p,8a,8b,16a#,8a,16g.,16e6,16g6,8a6,16f6,8g6,8e6,16c6,16d6,8b,8p,16g6 ,16f#6,16f6,16d#6,16p,16e6,16p,16g#,16a,16c6,16p,16a,16c6,16d6,8p,16g6,16f#6,16f6,16d#6,16p,16e6,16p,16c7,16p,16c7,16c7,p,16g6,16f#6,16f6,16d#6,16p,16e6,16p,16g#,16a,16c6,16p,16a,16c6,16d6,8p,16d#6,8p,16d6,8p,16c6";
char *song = "smb_under:d=4,o=6,b=100:32c,32p,32c7,32p,32a5,32p,32a,32p,32a#5,32p,32a#,2p,32c,32p,32c7,32p,32a5,32p,32a,32p,32a#5,32p,32a#,2p,32f5,32p,32f,32p,32d5,32p,32d,32p,32d#5,32p,32d#,2p,32f5,32p,32f,32p,32d5,32p,32d,32p,32d#5,32p,32d#";
char * nummer = "smbdeath:d=4,o=5,b=90:32c6,32c6,32c6,8p,16b,16f6,16p,16f6,16f.6,16e.6,16d6,16c6,16p,16e,16p,16c";
char * nummer = "ducktales:d = 4, o = 5, b = 112:8e6, 8e6, 16 p, 16 g 6, 8b6, g #6, p, 8e6, 8 d 6, 8 c, 6, 8 d 6, 8e6, 8 d 6, 8 c, 6, 8 d 6, 8e6, 8e6, 16 p, 16 g 6, 8b6, g #6, p, 8e6, 8 d 6, 8 c, 6, 8 d 6, 8e6, 8 d 6, 8 c, 6, 8 g 6, 8e6, 8e6";
char *song = "Zelda1:d=4,o=5,b=125:a#,f.,8a#,16a#,16c6,16d6,16d#6,2f6,8p,8f6,16f.6,16f#6,16g#.6,2a#.6,16a#.6,16g#6,16f#.6,8g#.6,16f#.6,2f6,f6,8d#6,16d#6,16f6,2f#6,8f6,8d#6,8c#6,16c#6,16d#6,2f6,8d#6,8c#6,8c6,16c6,16d6,2e6,g6,8f6,16f,16f,8f,16f,16f,8f,16f,16f,8f,8f,a#,f.,8a# 16a#,16c6,16d6,16d#6,2f6,8p,8f6,16f.6,16f#6,16g#.6,2a#.6,c#7,c7,2a6,f6,2f#.6,a#6,a6,2f6,f6,2f#.6,a#6,a6,2f6,d6,2d#.6,f#6,f6,2c#6,a#,c6,16d6,2e6,g6,8f6,16f,16f,8f,16f,16f,8f,16f,16f,8f,8f ";
char *song = "smario2:d=4,o=5,b=125:8g,16c,8e,8g.,16c,8e,16g,16c,16e,16g,8b,a,8p,16c,8g,16c,8e,8g.,16c,8e,16g,16c#,16e,16g,8b,a,8p,16b,8c6,16b,8c6,8a.,16c6,8b,16a,8g,16f#,8g,8e.,16c,8d,16e,8f,16e,8f,8b.4,16e,8d.,c";
char *song = "smb3lvl1:d=4,o=5,b=80:16g,32c,16g.,16a,32c,16a.,16b,32c,16b,16a.,32g#,16a.,16g,32c,16g.,16a,32c,16a,4b.,32p,16c6,32f,16c.6,16d6,32f,16d.6,16e6,32f,16e6,16d.6,32c#6,16d.6,16c6,32f,16c.6,16d6,32f,16d6,4e.6,32p,16g,32c,16g.,16a,32c,16a.,16b,32c,16b,16a.,32g#,16a.,16c6 , 8c.6,32p,16c6,4c.6 ";
char * nummer = "shinobi:d = 4, o = 5, b = 140:b f #6, d6, b, g, f #, e, 2f #., a, 1f # p, b, f #6, d6, b, g, f #, e, 1f #., 8a, 1b., 8a, 1f #., 8a, 1b., 8a, 1f #.";
char * nummer = "outrun_magic:d = 4, o = 5, b = 160:f6 d #6, 8 g #.6, f6, d #6, 8 c#.6, d #6, c6, 2 g #., c# 6, c6, 8 d #.6, c# 6, c6, 8f., een #, 16c.6, 1a #, f6, d #6, 8 g #.6, f6, d #6, 8 c#.6, d #6, c6, 2 g #., c# 6, c6, 8 d #.6, c# 6, c6, 16 septies., 16 g #., c6, 2a #.";
char *song = "Popeye:d=4,o=5,b=140:16g.,16f.,16g.,16p,32p,16c.,16p,32p,16c.,16p,32p,16e.,16d.,16c.,16d.,16e.,16f.,g,8p,16a,16f,16a,16c6,16b,16a,16g,16a,16g,8e,16g,16g,16g,16g,8a,16b,32c6,32b,32c6,32b,32c6,32b,8c6";
char * nummer = "Wonderboy:d = 4, o = 5, b = 225:f6, d6, f6, 8 d 6, f6, 32 p, 8f6, d6, f6, d6, e6, c6, e6, 8 c, 6, e6, 32 p, 8e6, c6, e6, c6";
char *song = "smwwd1:d=4,o=5,b=125:a,8f.,16c,16d,16f,16p,f,16d,16c,16p,16f,16p,16f,16p,8c6,8a.,g,16c,a,8f.,16c,16d,16f,16p,f,16d,16c,16p,16f,16p,16a#,16a,16g,2f,16p,8a.,8f.,8c,8a.,f,16g#,16f,16c,16p,8g#.,2g,8a.,8f.,8c,8a.,f,16g# , 16 septies, 8c, 2c 6";
char * nummer = "dkong:d = 4, o = 5, b = 160:2 c, 8 d., d #., c., 16b, 16 c 6, 16b, 16 c 6, 16b, 16 c 6, 16b, 16 c 6, 16b, 16 c 6, 16b, 16 c 6, 16b, 2 c 6";
char * nummer = "dkong:d = 4, o = 5, b = 160:2 c, 8 d., d #., c., 16b, 16 c 6, 16b, 16 c 6, 16b, 16 c 6, 16b, 16 c 6, 16b, 16 c 6, 16b, 16 c 6, 16b, 2 c 6";
void setup(void)
{
Serial.begin(9600);
tone1.begin(8);
}
#define isdigit(n) (n > = '0' & & n < = '9')
VOID play_rtttl(char *p)
{
Absoluut geen foutcontrole hier
byte-default_dur = 4;
byte default_oct = 6;
int bpm = 63;
int num;
lange wholenote;
lange duur;
byte Opmerking;
byte schaal;
formaat: d = N, o = N, b = NNN:
het vinden van het begin (skip naam, enz.)
terwijl (* p! = ':') p ++; negeren van de naam
p ++; overslaan ':'
standaardduur krijgen
Als (* p == had')
{
p ++; p ++; overslaan "d ="
num = 0;
while(isDigit(*p))
{
num = (num * 10) + (* p ++ - '0');
}
Als (num > 0) default_dur = num;
p ++; overslaan door komma 's
}
Serial.Print ("ddur:"); Serial.println (default_dur, 10);
krijgen standaard octave
Als (* p == ' o ')
{
p ++; p ++; overslaan "o ="
num = * p ++ - '0';
Als (num > = 3 & & num < = 7) default_oct = num;
p ++; overslaan door komma 's
}
Serial.Print ("Docto:"); Serial.println (default_oct, 10);
krijgen van de BPM
Als (* p == 'b')
{
p ++; p ++; overslaan "b ="
num = 0;
while(isDigit(*p))
{
num = (num * 10) + (* p ++ - '0');
}
BPM = num;
p ++; overslaan van de dikke darm
}
Serial.Print ("bpm:"); Serial.println (hsm, 10);
BPM meestal uitgedrukt in het aantal kwartnoten per minuut
wholenote = (60 * 1000L / bpm) * 4; Dit is de tijd voor hele notitie (in milliseconden)
Serial.Print ("wn:"); Serial.println (wholenote, 10);
nu beginnen Opmerking lus
while(*p)
{
Ten eerste, krijgen nota duur, indien beschikbaar
num = 0;
while(isDigit(*p))
{
num = (num * 10) + (* p ++ - '0');
}
if(NUM) duur = wholenote / num;
anders duur = wholenote / default_dur; zullen we om te controleren of we een gestippelde opmerking na
nu krijgen de notitie
Opmerking = 0;
switch(*p)
{
Case "c":
Opmerking = 1;
breken;
geval zou ':
Opmerking = 3;
breken;
Case "e":
Opmerking = 5;
breken;
Case "f":
Opmerking = 6;
breken;
Case 'g':
Opmerking = 8;
breken;
geval 'a':
Opmerking = 10;
breken;
Case "b":
Opmerking = 12;
breken;
letter 'p':
standaard:
Opmerking = 0;
}
p ++;
nu, krijgen optionele '#' scherpe
Als (* p == '#')
{
Opmerking ++;
p ++;
}
nu, krijgen optionele '.' gestippelde Opmerking
Als (* p == '.')
{
duur += duur/2;
p ++;
}
nu, krijgen schaal
if(isDigit(*p))
{
schaal = * p - '0';
p ++;
}
anders
{
schaal = default_oct;
}
schaal += OCTAVE_OFFSET;
Als (* p == ',')
p ++; komma voor de volgende notitie overslaan (of we kunnen aan het einde)
nu spelen de notitie
if(Note)
{
Serial.Print ("spelen:");
Serial.Print (schaal 10); Serial.Print(' ');
Serial.Print (toelichting, 10); Serial.Print ("(");
Serial.Print (notities [(scale-4) * 12 + Opmerking], 10);
Serial.Print(")");
Serial.println (duur, 10);
tone1.Play (notities [(scale-4) * 12 + Opmerking]);
delay(duration);
tone1.stop();
}
anders
{
Serial.Print ("onderbreken:");
Serial.println (duur, 10);
delay(duration);
}
}
}
void loop(void)
{
play_rtttl(Song);
Serial.println("done.");
while(1);
}