User:Amy Suo Wu/assignment 2
< User:Amy Suo Wu
Revision as of 12:19, 2 November 2010 by Amy Suo Wu (talk | contribs)
with help from Mr Stock
<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);
}