Étape 3: Entrez le code
nom de fichier pour cet exemple
char nom [] = "NEWSONG. JOURNAL";
toneline Char [5] ;
int n, titulaire ;
Puce SD sélectionnez NIP
const uint8_t chipSelect = SS ;
objet système de fichiers
SdFat sd ;
créer des flux de données série
ArduinoOutStream cout(Serial) ;
stocker les chaînes d’erreur en flash pour sauver RAM
#define erreur (s) sd.errorHalt_P(PSTR(s))
playtone int ;
dlay int ;
void setup()
{
pinMode (sortie 8) ;
pinMode (entrée, A5) ;
Serial.Begin(9600) ;
Si (! sd.begin (chipSelect, SPI_HALF_SPEED)) sd.initErrorHalt() ;
startupsong() ;
}
void loop()
{
Si (! sd.begin (chipSelect, SPI_HALF_SPEED)) sd.initErrorHalt() ;
ofstream sdout (nom, ios::out | ios::app) ;
Si (! sdout) erreur ("open failed") ;
Delay(200) ;
randomSeed(analogRead(5)) ;
/ * Si vous avez une broche analogique non-connectée,
il ira chercher un bruit aléatoire de la
milieu environnant (ondes radio,
rayons cosmiques, interférence electromag-netic
des téléphones cellulaires et les lampes fluorescentes,
et ainsi de suite). * /
dlayer long = random (180000) +180000 ;
/ * Ce code prévoyait un annoyer aléatoire avec au moins un retard de 3 minutes à l’origine. Ainsi, vous pouvez modifier le dlayer pour un temps plus court si vous voulez. */
int dlayer = 180000 ;
while (dlayer < 0) {dlayer = aléatoire +180000 (180000);}
Serial.end() ;
Serial.Begin(9600) ;
Serial.Print ("retard 1 est") ;
Serial.Print (dlayer/1000, DEC) ;
Serial.Print ("secondes, aprox") ;
Serial.Print (dlayer/1000/60, DEC) ;
Serial.println (« minutes ») ;
Delay(dlayer) ;
Playtone = random(2000) ;
Serial.Print ("ton 1 est") ;
Serial.println(Playtone) ;
ton (8, playtone) ;
Delay(50) ;
noTone(8) ;
Delay(50) ;
sdout << playtone << endl ;
sdout.Close() ;
Playtone = random(7000) ;
Serial.Print ("est de 2 Tone") ;
Serial.println(Playtone) ;
ton (8, playtone) ;
Delay(50) ;
noTone(8) ;
Delay(50) ;
sdout << playtone << endl ;
Playtone = random(5000) ;
Serial.Print ("ton 3 est") ;
Serial.println(Playtone) ;
ton (8, playtone) ;
Delay(50) ;
noTone(8) ;
Delay(50) ;
sdout << playtone << endl ;
sdout.Close() ;
readsong() ;
}
void startupsong() {}
Serial.println ("jouer la chanson démarrage.") ;
ton (8, 2500) ;
Delay(50) ;
noTone(8) ;
ton (8, 2500) ;
Delay(50) ;
noTone(8) ;
Delay(50) ;
ton (8, random(7000)) ;
Delay(Random(250)) ;
noTone(8) ;
Delay(50) ;
ton (8, random(5000)) ;
Delay(50) ;
noTone(8) ;
Delay(50) ;
}
void readsong() {}
SdFile rdfile ("SONG. OUVRIR UNE SESSION", O_READ) ;
tandis que ((n = rdfile.fgets (toneline, sizeof(toneline))) > 0) {}
/*
Si (toneline [n - 1] == « \n ») {}
cout < <> ' ' << toneline ;
} else {}
cout << « # » << toneline << endl ;
}
*/
titulaire = atoi(toneline) ;
ton (8, titulaire) ;
Delay(50) ;
noTone(8) ;
Delay(50) ;
Serial.Print("+") ;
Serial.println(Holder) ;
cout << titulaire << endl ;
}
char c ;
ifstream file ("SOUNDS. JOURNAL") ;
Si (! file.is_open()) sd.errorHalt ("open a échoué") ;
Copiez le fichier dans la série
tandis que ((c = file.get()) > = 0) cout << c ;
cout << « Fait » << endl ;
}