just started , struggling programming. trying combine force sensitive resistor code piezo squeezing force sensitive resistor turn piezo off. compiles doesn't work on board? trying finish high school project , appreciate advice.
thanks!
/* melody
* (cleft) 2005 d. cuartielles k3
*
* example uses piezo speaker play melodies. sends
* square wave of appropriate frequency piezo, generating
* corresponding tone.
*
* calculation of tones made following mathematical
* operation:
*
* timehigh = period / 2 = 1 / (2 * tonefrequency)
*
* different tones described in table:
*
* note frequency period timehigh
* c 261 hz 3830 1915
* d 294 hz 3400 1700
* e 329 hz 3038 1519
* f 349 hz 2864 1432
* g 392 hz 2550 1275
* a 440 hz 2272 1136
* b 493 hz 2028 1014
* c 523 hz 1912 956
*
* http://www.arduino.cc/en/tutorial/melody
*/
int sensepin = 2;
int speakerpin = 9;
int length = 15; // number of notes
char notes[] = "ccggaagffeeddc "; // space represents rest
int beats[] = { 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 4 };
int tempo = 300;
void playtone(int tone, int duration) {
(long = 0; < duration * 1000l; += tone * 2) {
digitalwrite(speakerpin, high);
delaymicroseconds(tone);
digitalwrite(speakerpin, low);
delaymicroseconds(tone);
}
}
void playnote(char note, int duration) {
char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c' };
int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956 };
// play tone corresponding note name
(int = 0; < 8; i++) {
if (names == note) {
playtone(tones, duration);
}
}
}
void setup() {
serial.begin(9600);
pinmode(speakerpin, output);
}
void loop() {
int value = analogread(sensepin) /4;
analogwrite(speakerpin, value);
(int = 0; < length; i++) {
if (notes == ' ') {
delay(beats * tempo); // rest
} else {
playnote(notes, beats * tempo);
}
// pause between notes
delay(tempo / 2);
}
}
thanks!
/* melody
* (cleft) 2005 d. cuartielles k3
*
* example uses piezo speaker play melodies. sends
* square wave of appropriate frequency piezo, generating
* corresponding tone.
*
* calculation of tones made following mathematical
* operation:
*
* timehigh = period / 2 = 1 / (2 * tonefrequency)
*
* different tones described in table:
*
* note frequency period timehigh
* c 261 hz 3830 1915
* d 294 hz 3400 1700
* e 329 hz 3038 1519
* f 349 hz 2864 1432
* g 392 hz 2550 1275
* a 440 hz 2272 1136
* b 493 hz 2028 1014
* c 523 hz 1912 956
*
* http://www.arduino.cc/en/tutorial/melody
*/
int sensepin = 2;
int speakerpin = 9;
int length = 15; // number of notes
char notes[] = "ccggaagffeeddc "; // space represents rest
int beats[] = { 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 4 };
int tempo = 300;
void playtone(int tone, int duration) {
(long = 0; < duration * 1000l; += tone * 2) {
digitalwrite(speakerpin, high);
delaymicroseconds(tone);
digitalwrite(speakerpin, low);
delaymicroseconds(tone);
}
}
void playnote(char note, int duration) {
char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c' };
int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956 };
// play tone corresponding note name
(int = 0; < 8; i++) {
if (names == note) {
playtone(tones, duration);
}
}
}
void setup() {
serial.begin(9600);
pinmode(speakerpin, output);
}
void loop() {
int value = analogread(sensepin) /4;
analogwrite(speakerpin, value);
(int = 0; < length; i++) {
if (notes == ' ') {
delay(beats * tempo); // rest
} else {
playnote(notes, beats * tempo);
}
// pause between notes
delay(tempo / 2);
}
}
please use code tags [i] corrupts listing.
Arduino Forum > Using Arduino > Programming Questions > Need help - Newbie with high school project
arduino
Comments
Post a Comment