User:Birgit bachler/clappingarduino: Difference between revisions

From XPUB & Lens-Based wiki
(Created page with "<source lang=c> int speakerPin = 13; int thedelay = 100; char pat[] = "xxx xx x xx "; int patlen = strlen(pat); void setup(){ } void loop (){ for(int up=0; up<patlen; ...")
 
No edit summary
 
Line 1: Line 1:
<source lang=c>
<source lang=c>
int speakerPin = 13;
int speakerPin = 13;
int thedelay = 100;
int thedelay = 10;


char pat[]  = "xxx xx x xx ";
char pat[]  = "xxx xx x xx ";
Line 20: Line 20:
          
          
         if (pat[i] == 'x') tone(speakerPin, 400, thedelay);
         if (pat[i] == 'x') tone(speakerPin, 400, thedelay);
         delay(thedelay);
         delay(10);
         if (pat[i2] == 'x') tone(speakerPin, 800, thedelay);
         if (pat[i2] == 'x') tone(speakerPin, 800, thedelay);
         delay(thedelay);     
         delay(thedelay*thedelay);     
     }   
     }   
     delay(thedelay);
     delay(thedelay*thedelay);
   }
   }
}
}
</source>
</source>

Latest revision as of 16:22, 1 November 2010

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