Änderungen

HackFFM-Duino Chime

2.599 Byte hinzugefügt, 23:12, 26. Sep. 2015
I also used libraries from sparkfun and adafruit.
== Arduino code (for use with SimpleSDAudio library) ==
<pre>
/*
Simple SD Audio bare minimum example, plays file EX1.MIX from root folder of SD card.
This example shows how to use the SimpleSDAudio library with Chime
http://hackerspace-ffm.de/wiki/index.php?title=HackFFM-Duino_Chime
See SimpleSDAudio.h or our website for more information:
http://www.hackerspace-ffm.de/wiki/index.php?title=SimpleSDAudio
created 27 Sep 2015 by Lutz Lisseck
*/
#include <SimpleSDAudio.h>
 
/* Chime Special function block start */
#define CHIME_GAIN_SW 2
#define CHIME_GAIN_EN A3
#define CHIME_SPK_EN A1
#define CHIME_LED 5
#define CHIME_SD_DET 8
#define CHIME_SD_CS 4
/* gain 0 off, 1 quiet, 2 loud */
void setupChime(unsigned char gain) {
pinMode(CHIME_GAIN_SW, OUTPUT);
pinMode(CHIME_GAIN_EN, OUTPUT);
pinMode(CHIME_SPK_EN, OUTPUT);
pinMode(CHIME_LED, OUTPUT); digitalWrite(CHIME_LED, LOW);
pinMode(CHIME_SD_DET, INPUT_PULLUP);
switch(gain) {
case 0: // off
digitalWrite(CHIME_SPK_EN, LOW);
digitalWrite(CHIME_GAIN_EN, HIGH);
digitalWrite(CHIME_GAIN_SW, LOW);
break;
case 1: // soft
digitalWrite(CHIME_SPK_EN, HIGH);
digitalWrite(CHIME_GAIN_EN, HIGH);
digitalWrite(CHIME_GAIN_SW, LOW);
break;
default: // loud
digitalWrite(CHIME_SPK_EN, HIGH);
digitalWrite(CHIME_GAIN_EN, LOW);
digitalWrite(CHIME_GAIN_SW, HIGH);
break;
}
SdPlay.setSDCSPin(CHIME_SD_CS);
}
/* Chime Special function block end */
 
void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(9600);
 
setupChime(2);
// Using F("...") to avoid wasting RAM
Serial.print(F("\nInitializing SD card..."));
if (!SdPlay.init(SSDA_MODE_FULLRATE | SSDA_MODE_STEREO | SSDA_MODE_AUTOWORKER)) {
Serial.println(F("initialization failed. Is FAT formated card inserted?"));
Serial.print(F("Error code: "));
Serial.println(SdPlay.getLastError());
while(1);
} else {
Serial.println(F("Wiring is correct and a card is present."));
}
 
Serial.print(F("Looking for EX1.MIX... "));
if(!SdPlay.setFile("EX1.MIX")) {
Serial.println(F(" not found on card! Error code: "));
Serial.println(SdPlay.getLastError());
while(1);
} else {
Serial.println(F("found."));
}
 
Serial.print(F("Playing... "));
SdPlay.play();
while(!SdPlay.isStopped()) {
; // no worker needed anymore :-)
delay(500);
digitalWrite(CHIME_LED, !digitalRead(CHIME_LED));
}
Serial.println(F("done."));
SdPlay.deInit();
}
 
void loop(void) {
 
}
</pre>
[[Kategorie:Projekte]]
1.995
Bearbeitungen