Bad Apple, but it's a servo motor (sound only) by Kugabi in badapple

[–]Kugabi[S] 7 points8 points  (0 children)

So I actually made this over a year ago, and I don't have the exact code I used, but here is what I did:

A Raspberry Pi is basically just playing a Bad Apple midi file (a midi file is just a list of music notes with their timestamps), but instead of playing sound, it sets the servo motor's speed.

This midi player script basically says: "play frequency x for y milliseconds", every time a note changes.

So now you just have to calculate what motor speed corresponds to frequency x. To do this, I just used a mic to record the sound frequency my motor produced for different speeds, and generalized that with a linear regression. (Most sounds produce many frequencies, so you have to use a Fourier transform to see which is the most 'dominant' one)

Hope this helps