User:Amy Suo Wu/assignment 2: Difference between revisions

From XPUB & Lens-Based wiki
No edit summary
No edit summary
 
Line 1: Line 1:
with help from Mr Stock
with help from Mr Stock


<source lang="bash">
<source lang="C">


int speakerPin = 13;
int speakerPin = 13;

Latest revision as of 22:58, 8 November 2010

with help from Mr Stock

<source lang="C">

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

}