Star Wars Imperial March With Piezo
i got sketch havent tried because different melody tones( guess call em that).
code have tried:
this work plays fur elise
so question is: code imperial march written controlling airvalve pulsing open , closed valve play imperial march song/tone looks alot different! can work on piezo buzzer same airvalve?? here code don't think work smarter may save me trouble , answer! here code
??
code have tried:
code: [select]
int speakerpin = 9;
char notes[] = "ededebdcaceabegbceededebdcaceabecbaededebdcaceabegbceededebdcaceabecbabcdegfedfedcedcbeeeededededededebdcaceabegbceededebdcaceabecba";
// e d e d e b d c c e b e g b c e e d|e d e b d c c e b e c b e d e d e b d c|a c e b e g b c e e d e d e b d c c e a|b e c b b c d e g f e d f e d c e d c|b e e e e d e d e d e d e d e d e b d c c e b e g b c e e d e d e b d c c e b e c b a
int beats[] = { 1,1,1,1,1,1,1,1,3,1,1,1,3,1,1,1,3,1,1,1,1,1,1,1,1,1,3,1,1,1,3,1,1,1,3,1,1,1,1,1,1,1,1,3,1,1,1,3,1,1,1,3,1,1,1,1,1,1,1,1,1,3,1,1,1,3,1,1,1,3,1,1,1,2,1,1,1,2,1,1,1,2,1,1,1,3,1,5,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,3,1,1,1,3,1,1,1,3,1,1,1,1,1,1,1,1,1,3,1,1,1,3,1,1,1,6};
int tempo = 175;
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', 'd', 'e', 'f', 'g', 'a', 'b', 'u'};
int tones[] = {3822,3424,3033,2864,2551,2272,2024, 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956};
// play tone corresponding note name
(int = 0; < sizeof(tones); i++) {
if (names[i] == note) {
playtone(tones[i], duration);
}
}
}
void setup() {
pinmode(speakerpin, output);
}
void loop() {
(int = 0; < sizeof(notes); i++) {
if (notes[i] == ' ') {
delay(beats[i] * tempo); // rest
} else {
playnote(notes[i], beats[i] * tempo);
}
// pause between notes
delay(tempo / 2);
if (i == sizeof(notes)-1){
delay(1000);
}
}
}
this work plays fur elise
so question is: code imperial march written controlling airvalve pulsing open , closed valve play imperial march song/tone looks alot different! can work on piezo buzzer same airvalve?? here code don't think work smarter may save me trouble , answer! here code
code: [select]
const int c = 261;
const int d = 294;
const int e = 329;
const int f = 349;
const int g = 391;
const int gs = 415;
const int = 440;
const int = 455;
const int b = 466;
const int ch = 523;
const int csh = 554;
const int dh = 587;
const int dsh = 622;
const int eh = 659;
const int fh = 698;
const int fsh = 740;
const int gh = 784;
const int gsh = 830;
const int ah = 880;
const int buzzerpin = 9; //digital pin 9
int counter = 0;
void setup()
{
//setup pin modes
pinmode(buzzerpin, output);
}
void loop()
{
//play first section
firstsection();
//play second section
secondsection();
//variant 1
beep(f, 250);
beep(gs, 500);
beep(f, 350);
beep(a, 125);
beep(ch, 500);
beep(a, 375);
beep(ch, 125);
beep(eh, 650);
delay(500);
//repeat second section
secondsection();
//variant 2
beep(f, 250);
beep(gs, 500);
beep(f, 375);
beep(ch, 125);
beep(a, 500);
beep(f, 375);
beep(ch, 125);
beep(a, 650);
delay(650);
}
void beep(int note, int duration)
{
//play tone on buzzerpin
tone(buzzerpin, note /4, duration);
//stop tone on buzzerpin
notone(buzzerpin);
delay(50);
//increment counter
counter++;
}
void firstsection()
{
beep(a, 500);
beep(a, 500);
beep(a, 500);
beep(f, 350);
beep(ch, 150);
beep(a, 500);
beep(f, 350);
beep(ch, 150);
beep(a, 650);
delay(500);
beep(eh, 500);
beep(eh, 500);
beep(eh, 500);
beep(fh, 350);
beep(ch, 150);
beep(gs, 500);
beep(f, 350);
beep(ch, 150);
beep(a, 650);
delay(500);
}
void secondsection()
{
beep(ah, 500);
beep(a, 300);
beep(a, 150);
beep(ah, 500);
beep(gsh, 325);
beep(gh, 175);
beep(fsh, 125);
beep(fh, 125);
beep(fsh, 250);
delay(325);
beep(as, 250);
beep(dsh, 500);
beep(dh, 325);
beep(csh, 175);
beep(ch, 125);
beep(b, 125);
beep(ch, 250);
delay(350);
}
work piezo first code/sketch listed?
quote
can work on piezo buzzer
of course not. going need huge speaker , big amplifier, being deaf.
Arduino Forum > Using Arduino > Programming Questions > Star Wars Imperial March With Piezo
arduino
Comments
Post a Comment