Archive | June, 2013

Source code with a TRON MELODY for sound with lilypad

9 Jun

int ledPin = 13; // LED is connected to digital pin 13

int speakerPin = 5; // speaker connected to digital pin 5

 

void setup()  

{  

  pinMode(ledPin, OUTPUT); // sets the ledPin to be an output

  pinMode(speakerPin, OUTPUT); // sets the speakerPin to be an output

}  

 

void loop() // run over and over again

{  

  scale(); // call the scale() function

  delay(1000); // delay for 1 second

}  

 

void beep (unsigned char speakerPin, int frequencyInHertz, long timeInMilliseconds)     // the sound producing function

{  

  int x;  

  long delayAmount = (long)(1000000/frequencyInHertz);

  long loopTime = (long)((timeInMilliseconds*1000)/(delayAmount*2));

  for (x=0;x<loopTime;x++)  

  {  

    digitalWrite(speakerPin,HIGH);

    delayMicroseconds(delayAmount);

    digitalWrite(speakerPin,LOW);

    delayMicroseconds(delayAmount);

  }  

}  

 

void scale ()

{  

  digitalWrite(ledPin,HIGH); //turn on the LED

 beep(speakerPin,313,375); //

beep(speakerPin,370,375); //

beep(speakerPin,313,125); //

beep(speakerPin,1245,125); //

beep(speakerPin,932,125); //

beep(speakerPin,740,125); //

beep(speakerPin,554,125); //

beep(speakerPin,415,125); //

beep(speakerPin,277,125); //

beep(speakerPin,415,125); //

beep(speakerPin,370,125); //

beep(speakerPin,440,125); //

 

  digitalWrite(ledPin,LOW); //turn off the LED

}  

 

 

Advertisements
Link

LILYPAD ARDUINO Y TEXTILES INTELIGENTES 1.

9 Jun

LILYPAD ARDUINO Y TEXTILES INTELIGENTES 1.