[PHOTON] GoT Theme

Hi guys ! I want to play the GoT theme with my Internet Button but it won’t work ! Each sound work perfectly when I use it alone … But when I use all of them it fail, any idea ?

// This #include statement was automatically added by the Particle IDE.
#include "InternetButton/InternetButton.h"

InternetButton b = InternetButton();

void setup() {
    //initiating Internet button
    b.allLedsOff();
    b.begin();
}

void loop() {
    //for(int i=0; i<4; i++)
    {
    b.playSong("G4");
    delay(500);
    b.playSong("C4");
    delay(500);
    b.playSong("DS4");
    delay(250);
    b.playSong("F4");
    delay(250);
    }
    for(int i=0; i<4; i++)
    {
    b.playSong("G4");
    delay(500);
    b.playSong("C4");
    delay(500);
    b.playSong("E4");
    delay(250);
    b.playSong("F4");
    delay(250);
    }
        b.playSong("G4");
        delay(500);
        
        b.playSong("C4");
        delay(500);
        b.playSong("DS4");
        delay(250);
        
        b.playSong("F4");
        delay(250);
        
        b.playSong("D4");
        delay(500);
        
    for(int i=0; i<3; i++)
    {
    b.playSong("G3");
    delay(500);
    
    b.playSong("AS3");
    delay(250);
    
    b.playSong("C4");
    delay(250);
    
    b.playSong("D4");
    delay(500);
    
    }//
        b.playSong("G3");
        delay(500);
        
        b.playSong("AS3");
        delay(250);
        
        b.playSong("C4");
        delay(250);
        
        b.playSong("D4");
        delay(1000);
        
        
        b.playSong("F4");
        delay(1000);
        
        b.playSong("AS3");
        delay(1000);
        
        b.playSong("DS4");
        delay(250);
        
        b.playSong("D4");
        delay(250);
        
        b.playSong("F4");
        delay(1000);
        
        b.playSong("AS3");
        delay(1000);
        
        b.playSong("DS4");
        delay(250);
        
        b.playSong("D4");
        delay(250);
        
        b.playSong("C4");
        delay(500);
    for(int i=0; i<3; i++)
    {
    b.playSong("GS3");
    delay(250);
    
    b.playSong("AS3");
    delay(250);
    
    b.playSong("C4");
    delay(500);
    
    b.playSong("F3");
    delay(500);
    
    }
          b.playSong("G4");
          delay(1000);
          
          b.playSong("C4");
          delay(1000);
          
          b.playSong("DS4");
          delay(250);
          
          b.playSong("F4");
          delay(250);
          
          b.playSong("G4");
          delay(1000);
          
          b.playSong("C4");
          delay(1000);
          
          b.playSong("DS4");
          delay(250);
          
          b.playSong("F4");
          delay(250);
          
          b.playSong("D4");
          delay(500);
          
    for(int i=0; i<4; i++)
    {
    b.playSong("G3");
    delay(500);
    
    b.playSong("AS3");
    delay(250);
    
    b.playSong("C4");
    delay(250);
    
    b.playSong("D4");
    delay(500);
    
    }
}

You can play a “sentence” too

https://build.particle.io/build/5774c8cf00b5894409001f9e/lib/57210a0343abd673f40004a3/tab/8_MakingMusic.cpp

    // playSong takes a string in the format
    // "NOTE,TYPE,NOTE,TYPE..."
    // Types are note types that define duration so 
    // 8 is a 1/8th note and 4 is a 1/4 note
    b.playSong("C4,8,E4,8,G4,8,C5,8,G5,4");

Try this :wink:

void loop() {
    b.allLedsOff();
    b.ledOn(1,10,10,10);
    for(int i=0; i<4; i++)
      b.playSong("G4,2,C4,2,D4,1,F4,1");
      //b.playSong("G4,2,C4,2,DS4,1,F4,1");

    b.ledOn(2,10,10,10);
    for(int i=0; i<4; i++)
      b.playSong("G4,2,C4,2,E4,1,F4,1");
      //b.playSong("G4,2,C4,2,E4,1,F4,1");
  
    b.ledOn(3,10,10,10);
    b.playSong("G4,2,C4,2,D4,1,F4,1,D4,2");
    //b.playSong("G4,2,C4,2,DS4,1,F4,1,D4,2");

    b.ledOn(4,10,10,10);
    for(int i=0; i<3; i++)
      b.playSong("G3,2,A3,1,C4,1,D4,2");
      //b.playSong("G3,2,AS3,1,C4,1,D4,2");

    b.ledOn(5,10,10,10);
    b.playSong("G3,2,A3,C4,1,D4,4,F4,4,A3,4,D4,1,D4,1,F4,4,A3,4,D4,1,D4,1,C4,2");
    //b.playSong("G3,2,AS3,C4,1,D4,4,F4,4,AS3,4,DS4,1,D4,1,F4,4,AS3,4,DS4,1,D4,1,C4,2");

    b.ledOn(6,10,10,10);
    for(int i=0; i<3; i++)
        b.playSong("G3,1,A3,1,C4,2,F3,2");
        //b.playSong("GS3,1,AS3,1,C4,2,F3,2");

    b.ledOn(7,10,10,10);
    b.playSong("G4,4,C4,4,D4,1,F4,1,G4,4,C4,4,D4,1,F4,1,D4,2");
    //b.playSong("G4,4,C4,4,DS4,1,F4,1,G4,4,C4,4,DS4,1,F4,1,D4,2");

    b.ledOn(8,10,10,10);
    for(int i=0; i<4; i++)
        b.playSong("G3,2,A3,1,C4,1,D4,2");
        //b.playSong("G3,2,AS3,1,C4,1,D4,2");
        
    delay(1000);
}

But I don’t think there are sharp/flat notes in the standard InternetButton library. Adding them, would not be hard tho’.

2 Likes

Wow thanks ! It work perfectly now :wink:

Just had a typo in the last but one sentence (40 instead of 4) :blush:

1 Like

If you want to play half-tones too, you can remove the InternetButton library from your project and just add two file tabs to your project and copy-paste a slightly modified InternetButton library

https://github.com/ScruffR/InternetButton/blob/master/firmware/InternetButton.h
https://github.com/ScruffR/InternetButton/blob/master/firmware/InternetButton.cpp

This way you can use half-tones with # and b like this

void loop() {
    b.allLedsOff();
    b.ledOn(1,10,10,10);
    for(int i=0; i<4; i++)
      b.playSong("G4,2,C4,2,D#4,1,F4,1");

    b.ledOn(2,10,10,10);
    for(int i=0; i<4; i++)
      b.playSong("G4,2,C4,2,E4,1,F4,1");

    b.ledOn(3,10,10,10);
    b.playSong("G4,2,C4,2,D#4,1,F4,1,D4,2");

    b.ledOn(4,10,10,10);
    for(int i=0; i<3; i++)
      b.playSong("G3,2,A#3,1,C4,1,D4,2");

    b.ledOn(5,10,10,10);
    b.playSong("G3,2,A#3,C4,1,D4,4,F4,4,A#3,4,D#4,1,D4,1,F4,4,A#3,4,D#4,1,D4,1,C4,2");

    b.ledOn(6,10,10,10);
    for(int i=0; i<3; i++)
        b.playSong("G#3,1,A#3,1,C4,2,F3,2");

    b.ledOn(7,10,10,10);
    b.playSong("G4,4,C4,4,D#4,1,F4,1,G4,4,C4,4,D#4,1,F4,1,D4,2");

    b.ledOn(8,10,10,10);
    for(int i=0; i<4; i++)
        b.playSong("G3,2,A#3,1,C4,1,D4,2");
}

Hey, thanks for your support ! Badly I can’t use your your two files. When i had them at the project a lot of warning appears and the flash became unsuccesful… =/

If you could show your error messages and a screenshot of your Build window (with the code drawer open)I might be able to help.
I guess it’s due to the coexistence of two libraries of the same name.

You need to remove the official InternetButton library and these lines

// This #include statement was automatically added by the Particle IDE.
#include "InternetButton/InternetButton.h"

and instead have this

#include "InternetButton.h"  // or however you named the files when you copy pasted them

@Cjak, these warnings are worth nothing. You’d need to scroll down the list till you find an error message. Only errors prevent a build.
You haven’t shown the code drawer open in your screenshot (light gray bar when you click < >).

1 Like

Ah sorry, here an other picture with my code drawer :

As I expected!
I mentioned earlier

In order to remove the library you need to click the (X) icon next to the library name under Included libraries!

Otherwise you keep declaring everything in the two versions of the lib twice - hence the multiple definition errors!

Wow i’m so stupid, it’s working perfectly now

1 Like