Sorry But I'm learning how to write some code, slowly picking up bits here and there but will need some help, Please
This code boots up and continuously plays the sound file over and over, but I would like it to only play once on each bootup .
any help!!
Thanks in advance.
/*
SOMO-14D
Control a SOMO-14D module to play sounds
*/
const int clockPin = 3; // the pin number of the clock pin
const int dataPin = 4; // the pin number of the data pin
const int resetPin = 6; // the pin number of the reset pin
const unsigned int PLAY_PAUSE = 0xFFFE;
const unsigned int STOP = 0xFFFF;
void setup() {
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(resetPin, OUTPUT);
digitalWrite(clockPin, HIGH);
digitalWrite(dataPin, LOW);
// reset the module
digitalWrite(resetPin, HIGH);
delay(100);
digitalWrite(resetPin, LOW);
delay(10);
digitalWrite(resetPin, HIGH);
delay(100);
}
void loop() {
// play "0001.ad4"
sendCommand(0x0001);
delay(5500);
// stop playing
sendCommand(STOP);
delay(100);
}
void sendCommand(unsigned int command) {
// start bit
digitalWrite(clockPin, LOW);
delay(2);
// bit15, bit14, ... bit0
for (unsigned int mask = 0x8000; mask > 0; mask >>= 1) {
if (command & mask) {
digitalWrite(dataPin, HIGH);
}
else {
digitalWrite(dataPin, LOW);
}
// clock low
digitalWrite(clockPin, LOW);
delayMicroseconds(200);
// clock high
digitalWrite(clockPin, HIGH);
delayMicroseconds(200);
}
// stop bit
delay(2);
}
You are missing how to post code. Go back and modify that last post. Select the code and hit the #icon and then save it.
If the first code you posted works then what is the second?
Saved code. does that look right.
first code is with working loop() which I don't want.
Second code is with no loop() and code pasted into setup() as you said, but no sound working?
OK fine, not lets hack this problem once and for all. It looks like the unit only plays on the second time of asking, which doesn't sound right. It could be that it needs the stop command from switch on so try and put that in first.
So go back to code 2 and insert a sendCommand(STOP);
between the end of the original setup and the start of the stuff that used to be in loop() and see if that works.