Just started playing around making sounds with the arduino. Wrote a quick function to output a frequency at a length to the board.
void sound(int freq, int millisec)
{
int period;
long cycles;
long i;
period = (500000 / freq);
cycles = ((long)freq * (long)millisec) / 1000;
for (i=0; i<= cycles; i++){
digitalWrite(SPKR_PIN, HIGH);
delayMicroseconds(period);
digitalWrite(SPKR_PIN, LOW);
delayMicroseconds(period);
}
}
Works great, however too simplistic. Looking into a library which translates wav files into arrays. I should be able to modify this function to feed those arrays through to make some sweet sweet music.
No comments:
Post a Comment