img_0671.mov |
float sinVal;
int toneVal;
int k=0;
void setup () {
pinMode(8,OUTPUT);
}
void loop () {
while (k< 2000){
for (int x=0;x<180;x++) {
// convert degrees to radians then obtain sin value
sinVal = (sin(x*(3.1412/180)));
// generate a frequency from the sin value
toneVal = 2000+(int(sinVal*1000));
tone(8, toneVal);
k++;
delay(2);
}}
for (int x=0;x<180;x++) {
// convert degrees to radians then obtain sin value
sinVal = (sin(x*(3.1412/180)));
// generate a frequency from the sin value
toneVal = 2000+(int(sinVal*1000));
tone(8, toneVal);
delay(5);}
}
In our pre calc class, we have talked about periods, amplitudes, and frequencies of the sin wave. In this Arduino Project, we were given a code that repeats the sound of the sin wave over and over again. What we had to do was to find the code that will make the Arduino make a sound for 5 seconds then make make another sound but have it be faster. Unfortunately, our project did not go quite as planned. We literally took a whole class period trying to figure out this code, but did not get anything. Luckily our teacher was able to figure something out and gave us this code that is written on the top. The amplitude is changed by changing the number that is in front of the sin, where the code says sinVal. The period is changed by changing the number in front of x in the same spot.
int toneVal;
int k=0;
void setup () {
pinMode(8,OUTPUT);
}
void loop () {
while (k< 2000){
for (int x=0;x<180;x++) {
// convert degrees to radians then obtain sin value
sinVal = (sin(x*(3.1412/180)));
// generate a frequency from the sin value
toneVal = 2000+(int(sinVal*1000));
tone(8, toneVal);
k++;
delay(2);
}}
for (int x=0;x<180;x++) {
// convert degrees to radians then obtain sin value
sinVal = (sin(x*(3.1412/180)));
// generate a frequency from the sin value
toneVal = 2000+(int(sinVal*1000));
tone(8, toneVal);
delay(5);}
}
In our pre calc class, we have talked about periods, amplitudes, and frequencies of the sin wave. In this Arduino Project, we were given a code that repeats the sound of the sin wave over and over again. What we had to do was to find the code that will make the Arduino make a sound for 5 seconds then make make another sound but have it be faster. Unfortunately, our project did not go quite as planned. We literally took a whole class period trying to figure out this code, but did not get anything. Luckily our teacher was able to figure something out and gave us this code that is written on the top. The amplitude is changed by changing the number that is in front of the sin, where the code says sinVal. The period is changed by changing the number in front of x in the same spot.