Arduino Music Help! How to make sound Without use Tone function?

Arduino Music Help!

How it does possible to write a arduino code to make the music without use the Tone Function? And make sounds?

Below is the code I found from https://www.arduino.cc/en/Tutorial/PlayMelody

But, I want to use arduino to make sound without the Tune Function. How can I do it?

/* Play Melody


  • Program to play melodies stored in an array, it requires to know
  • about timing issues and about how to play tones.
  • The calculation of the tones is made following the mathematical
  • operation:
  • timeHigh = 1/(2 * toneFrequency) = period / 2
  • where the different tones are described as in the table:
  • note frequency period PW (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
  • (cleft) 2005 D. Cuartielles for K3
    */

int ledPin = 13;
int speakerOut = 9;
byte names = {‘c’, ‘d’, ‘e’, ‘f’, ‘g’, ‘a’, ‘b’, ‘C’};
int tones = {1915, 1700, 1519, 1432, 1275, 1136, 1014, 956};
byte melody = “2d2a1f2c2d2a2d2c2f2d2a2c2d2a1f2c2d2a2a2g2p8p8p8p”;
// count length: 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0
// 10 20 30
int count = 0;
int count2 = 0;
int count3 = 0;
int MAX_COUNT = 24;
int statePin = LOW;

void setup() {
pinMode(ledPin, OUTPUT);
}

void loop() {
analogWrite(speakerOut, 0);
for (count = 0; count < MAX_COUNT; count++) {
statePin = !statePin;
digitalWrite(ledPin, statePin);
for (count3 = 0; count3 <= (melody[count2] - 48) * 30; count3++) {
for (count2=0;count2<8;count2++) {
if (names[count2] == melody[count
2 + 1]) {
analogWrite(speakerOut,500);
delayMicroseconds(tones[count2]);
analogWrite(speakerOut, 0);
delayMicroseconds(tones[count2]);
}
if (melody[count*2 + 1] == ‘p’) {
// make a pause of a certain size
analogWrite(speakerOut, 0);
delayMicroseconds(500);
}
}
}
}
}

You’ll do better enclosing your code inside [ code ] tags, as opposed to the quote that you used in your post.

Can you tell us why you don’t want to use tone()?

Here's one way: http://forum.arduino.cc/index.php?topic=179761.0

It is likely that any method will use the same timer that the Tone function does, so if you want to avoid Tone because of that you will have to be a lot more specific about what you want to do that Tone does not.

You could try this: http://www.thingiverse.com/thing:11214 The sound quality can be a bit harsh, depending on your speakers, and it takes trial and error to change the pitches, since the numbers in the code do not correspond to Hz. I'm sure that they are linear, though -- going from C to C#, for instance, is the same interval as from C# to D. Hope this helps!