Newbie need help !

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);
}

but I would like it to only play once on each bootup .

So move all the code in loop() to the startup() function and leave loop() blank.

Thanks for your help but i have tried that and got no sound. must be missing something else.

/*
  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);
  
  // play "0001.ad4"
  sendCommand(0x0001);
  delay(5500);

   // stop playing
  sendCommand(STOP);
  delay(100);
  
    }

void loop() {
  
}

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);
}

must be missing something else.

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?

First post was with the loop() and second was with no loop() and code pasted into setup() was that wrong.

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?

Yes the first and second codes both look fine to me. They both compile and I can't see any difference between them.

I modified the first code to just run once but it is the same as the second one.

/*
  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);

  }
boolean notPlayed = true;
void loop() {
  if(notPlayed){
  // play "0001.ad4"
  sendCommand(0x0001);
  delay(5500);

   // stop playing
  sendCommand(STOP);
  delay(100);
  notPlayed = false;
  }
  
}

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);
}

Tried your code but no sound.

The fisrt code is with loop The second is blank.

Sorry but you are doing something wrong if code 1 works and code 2 doesn't.

Maybe your wave player needs a power down between different codes?

yes code 1 works as a loop() which plays over and over,But I dont won't that.

I only want it to play once, which is the second code but its not working.

Your code doesn't work either. sorry if this is confusing you.

It might be that your unit only plays on the second time of asking. This code plays the sound twice:-

/*
  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);

  }
int played = 0;
void loop() {
  if(played < 2){
  // play "0001.ad4"
  sendCommand(0x0001);
  delay(5500);

   // stop playing
  sendCommand(STOP);
  delay(100);
  played++;
  }
  
}

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);
}

Thanks Mike that last code you did works perfect.

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.