Shop OBEX P1 Docs P2 Docs Learn Events
Question on Piezo Speaker? — Parallax Forums

Question on Piezo Speaker?

Mantine017Mantine017 Posts: 1
edited 2007-06-26 02:21 in General Discussion
does anybody know where i can find people who have taken midis for example mary
had a little lamb and translated it to basic stamp code so that piezo speaker would play it.
Im aware that there is one for mary had a little lamb but i was wondering if there was a site
where other midis have been broken down.
Thanks For Reading
Sincerely,
ConfusedPerson
confused.gif

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2004-10-25 03:19
    I doubt anyone has made it a project to convert a bunch of music to PBASIC, however using the code for 'Mary had a little lamb' you should be able to convert other music given the sheet music or musical notes.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage

    Knight Designs
    324 West Main Street
    P.O. Box 97
    Montour Falls, NY 14865
    (607) 535-6777

    Business Page:·· http://www.knightdesigns.com
    Personal Page:··· http://www.lightlink.com/dream/chris
    Designs Page:··· http://www.lightlink.com/dream/designs
    ·
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2004-10-30 19:08
    A recent issue of Nuts and Volts discussed creation of a musical scale as output on a microcontroller.· You just have to get the music, provide it as a data array [noparse][[/noparse]possibly two loops with two arrays - one for the tone, and one for the timing] and then have a main loop run the music.

    It does get a bit complicated because the PBasic only supports one dimension arrays - so you have to nest the two components [noparse][[/noparse]tone and length of tone] and make sure they arrive at the output together.

    Of course you can go a more sophisticated route if you want really musical sounding music.· I have seen some boards that support cell phone output using a BasicStamp.· It is up to you.· What do you want to learn?· And what do you really want to have?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    G. Herzog in Taiwan
  • Glenn AndersonGlenn Anderson Posts: 1
    edited 2007-06-25 20:53
    I have made a header file that makes it easier to convert musical notes to the Boe-Bot.
    Here is the code for the variable constants that refer to the musical notes.
    You can take a sheet of music and put the notes in by hand. It's time consuming but it works.
    I have attached files to show how it works.

    ' MusicConstants.BS2
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    ' MUSIC CONSTANTS
    x VAR Byte
    x = 4 'Change the port for the speaker here
    ' TIME VALUES WHOLE, DOTTED HALF, HALF, DOTTED QUARTER, QUARTER, EIGHTH, SIXTEENTH
    W CON 750
    DH CON 553
    H· CON 375
    DQ CON 250
    Q· CON 180
    E· CON 84
    S· CON 55
    'LOW NOTES
    NC1· CON 523
    NCS1 CON 554
    ND1· CON 587
    NDS1 CON 622
    NE1· CON 659
    NF1· CON 698
    NFS1 CON 739
    NG1· CON 783
    NGS1 CON 830
    NA1· CON 880
    NAS1 CON 932
    NB1· CON 987
    'MID NOTES
    NC2· CON 1046
    NCS2 CON 1106
    ND2· CON 1174
    NDS2 CON 1244
    NE2· CON 1318
    NF2· CON 1396
    NFS2 CON 1479
    NG2· CON 1567
    NGS2 CON 1661
    NA2· CON 1760
    NAS2 CON 1964
    NB2· CON 1975
    ' HIGH NOTES
    NC3· CON 2093
    NCS3 CON 2217
    ND3· CON 2344
    NDS3 CON 2489
    NE3· CON 2637
    NF3· CON 2793
    NFS3 CON 2959
    NG3· CON 3135
    NGS3 CON 3322
    NA3· CON 3520
    NAS3 CON 3729
    NB3· CON 3951
    NC4· CON 4380
  • jeffjohnvoljeffjohnvol Posts: 197
    edited 2007-06-26 02:21
    I had to do something like this during my undergrad days at UT. But we had to use 68HC11's to do it, and our piece was Beethoven's Fur Elise (sp?). We had to drive a speaker on, off, on, off, at a frequency that actually produced notes. It should be even easier by putting a PWM at a pin with a stamp.

    I do remember that the important thing is to have a gap in between notes. Otherwise, it all blends together and sounds horrible.
Sign In or Register to comment.