Rest between 2 notes

I am trying to code a song using the piezo buzzer. However, I need to play a note twice at multiple parts of the song(equivalent to pressing a note, lifting your finger, then pressing it again on a piano). I tried using tone(8,0), but it just creates a scratchy noise. the code is attached.

#include <sketch_dec25b.h>
int x = 1000;
void setup(){
}

void loop(){
tone(8,sa_high) ;
delay(x);
tone(8,ni);
delay(x);
tone(8,dha,500);
delay(x);
 ;
delay(x);
tone(8,dha,500);
delay(x);
 ;
delay(x);
tone(8,dha,500);
delay(x);
 ;
delay(x);
tone(8,dha);
delay(x);
tone(8,re_high);
delay(x);
tone(8,ni);
delay(x);
tone(8,pa);
delay(x);
 ;
delay(x);
tone(8,pa);
delay(x);
tone(8,ma_tivra);
delay(x);
tone(8,pa);
delay(x);
tone(8,re);
delay(x);
tone(8,ga);
delay(x);
tone(8,ma);
delay(x);
 ;
delay(x);
tone(8,ma);
delay(x);
 ;
delay(x);
tone(8,ma);
delay(x);
tone(8,dha);
delay(x);
tone(8,sa_high);
delay(x);
tone(8,dha);
delay(x);
tone(8,ma);
delay(x);
tone(8,pa);
delay(x);
tone(8,ma);
delay(x);
tone(8,ga);






delay(x);
tone(8,dha);
delay(x);
tone(8,ni);
delay(x);
tone(8,sa_high);
delay(x);
tone(8,re_high);
delay(x);
tone(8,re_high);
delay(x);
 ;
delay(x);
tone(8,re_high);
 ;
delay(x);
delay(x);
tone(8,dha);
delay(x);
tone(8,ni);
delay(x);
tone(8,sa_high);
delay(x);
 ;
delay(x);
tone(8,sa_high);
delay(x);
 ;
delay(x);
tone(8,sa_high);
delay(x);
 ;
delay(x);
tone(8,sa_high);
delay(x);
 ;
delay(x);
tone(8,sa_high);
delay(x);
tone(8,dha);
delay(x);
tone(8,pa);
delay(x);
tone(8,ma);
delay(x);
 ;
delay(x);
tone(8,ma);
delay(x);
tone(8,pa);
delay(x);
tone(8,ni);
delay(x);
 ;
delay(x);
tone(8,ni);
delay(x);
tone(8,sa_high);
delay(x);
 ;
delay(x);
tone(8,sa_high);
delay(x);
tone(8,ni);
delay(x);
tone(8,dha);
delay(x);

tone(8,ga_komal_high);
delay(x);
tone(8,re_high);
delay(x);
tone(8,sa_high);
delay(x);
 ;
delay(100);
tone(8,sa_high);
delay(x);
delay(100);
tone(8,sa_high);
delay(x);
delay(100);
tone(8,sa_high);
delay(x);




}

and here's the library

#define sa 240
#define re 270
#define ga 300
#define ma 320
#define pa 360
#define dha 400
#define ni 450
#define sa_high 480
#define re_high 540
#define ga_high 600
#define ma_tivra 340
#define ga_komal_high 576
#define ni_komal 432
#define komal_dha 384

You don't need your delay()s. You can use the duration parameter on tone() e.g.

// Instead of 
tone(8,sa_high);
delay(1000);  
//try
tone(8, sa_high, 1000);

Then when you want clearly separated notes you can use something like

tone(8, sa_high, 900);
delay(100);

You can adjust the 900/100 values until it sounds right to you provided they add up to 1000.

Steve

Have you considered using the third parameter of tone() to set the duration of the tone or perhaps the noTone() function to stop the tone playing when you want to ?

See tone() function