I've got the Melody function working with a piezo buzzer, but I'm actually trying to generate creepy sci-fi type sounds like a sonic screwdriver or a ray gun or that theremin sound from twilight zone and such. I don't want to use a speaker, just a buzzer. It shouldn't really be that difficult, I just have a terrible ear and couldn't deconstruct a sound if my life depended on it.
Here's what a sonic screwdriver sounds like, for reference:
http://soundfxnow.com/sound-fx/doctor-who-sonic-screwdriver/Here's the sorta-kinda-wibbly-wobbly code I've got running the buzzer right now.
It's close, but it's pretty irritating and I'd like to smooth it out and get it doing that nice oscillating thing. (I don't want to build an oscillator either. I'm mostly a software person, so I prefer to do it with code rather than more components)
Anyway, here it is. It probably just needs small adjustments from someone with a more trained ear:
tone(buzzerPin,2200); // then buzz by going high
tone(buzzerPin,1000);
tone(buzzerPin,500);
tone(buzzerPin,200);
tone(buzzerPin,500);
delayMicroseconds(10000); // waiting
noTone(buzzerPin); // going low
delayMicroseconds(10000); // and waiting more
tone(buzzerPin,2200);
tone(buzzerPin,1000);
delayMicroseconds(10000); // waiting
noTone(buzzerPin); // going low
delayMicroseconds(10000); // and waiting more
tone(buzzerPin,100);
delayMicroseconds(10000); // waiting
noTone(buzzerPin); // going low
delayMicroseconds(10000); // and waiting more
tone(buzzerPin,100);
delayMicroseconds(10000); // waiting
noTone(buzzerPin); // going low
delayMicroseconds(10000); // and waiting more