User:Birgit bachler/clappingarduino

From XPUB & Lens-Based wiki
int speakerPin = 13;
int thedelay = 10;

char pat[]  = "xxx xx x xx ";
int patlen = strlen(pat);
 
void setup(){
}
 
void loop (){
  
  for(int up=0; up<patlen; up++){
    for(int i=0; i<patlen; i++){

        int i2=i+up;
        if (i2>(patlen-1)){
          i2=i-patlen+up;
        }
        
        if (pat[i] == 'x') tone(speakerPin, 400, thedelay);
        delay(10);
        if (pat[i2] == 'x') tone(speakerPin, 800, thedelay);
        delay(thedelay*thedelay);    
    }  
    delay(thedelay*thedelay);
  }
}