User:Amy Suo Wu/assignment 2: Difference between revisions
Amy Suo Wu (talk | contribs) (Created page with "<source: bash> int speakerPin = 13; int thedelay = 100; // delay=milli-second char pat[] = "xxx xx x xx "; int patlen = strlen(pat); //strlen = string length void setup() {...") |
Amy Suo Wu (talk | contribs) No edit summary |
||
Line 1: | Line 1: | ||
<source | <source lang="bash"> | ||
int speakerPin = 13; | int speakerPin = 13; |
Revision as of 15:11, 30 October 2010
<source lang="bash">
int speakerPin = 13; int thedelay = 100; // delay=milli-second
char pat[] = "xxx xx x xx "; int patlen = strlen(pat); //strlen = string length
void setup() { }
int s = 0;
void loop () {
int i = 0; int i2 = 0; while (i<patlen) { i2 = i+s; if (i2 >= patlen) i2 = i2 - patlen; // maybe the % modulo operator could help here!!! if (pat[i] == 'x') tone(speakerPin, 400, 10); delay(10); if (pat[i2] == 'x') tone(speakerPin, 800, 10); delay(thedelay); i = i+1; } s = s+1; if (s >= patlen) s = 0; delay(thedelay*10);
}