User:Yiorgos Bagakis/prototyping/assignment2
< User:Yiorgos Bagakis
Revision as of 22:40, 1 November 2010 by Yiorgos Bagakis (talk | contribs) (Created page with "I tried to think of the way I would translate the clapping music exercise into C. I felt a bit hopeless and confused so I went through the first 7 tutorials on the Arduino websit...")
I tried to think of the way I would translate the clapping music exercise into C. I felt a bit hopeless and confused so I went through the first 7 tutorials on the Arduino website. Things started makle more sense :)
So having connected the speaker with an Arduino board and my computer I first worked on the tone function to familiarize myself with. I created my own pattern and adjusted the values of the Tone function (the fraequency) to create 3 different notes for the pattern:
int sPin = 13; //This is the speaker on Pin 13
int dly = 30; //I set the delay with a value 13
char pa[] = "xyzyxz yxzxyz"; // The pattern pa variable
int palen = strlen(pa); // The length of the pattern - in this case 13
void setup()
{
}
void loop()
{
for(int i=0; i<palen; i++) // Play the notes (palen) times. in this case 13
{
if (pa[i] == 'x') tone(sPin, 100, dly); delay(dly); //Define note x
if (pa[i] == 'y') tone(sPin, 500, dly); delay(dly); //Define note y
if (pa[i] == 'z') tone(sPin, 900, dly); delay(dly); //Define note z
}
}