NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.
Microcontroller Programming » Question in Making music with MCU project
March 01, 2011 by meeser |
Hi, my Nerdkits's just arrived several days ago. I've gone through all exercises in the Nerdkits guide and now I'm working on the Making music with MCU project. I have question on the play_tone function in the source code provided. Actually at first I cannot understand it so I try to write the code in the way I understand (no switch):
where the duration is in millisecond, which is just directly comes from: duration = 2xdelayxcycles (I also change (duration)DUR to 400) But it turns out to have a strange behavior, it plays each note very fast and when I increase the duration sometimes it becomes even faster. After that I just copy the play_tone function from the source code provided and it works fine..
(duration:DUR=40) I'm wondering if someone could explain me why we have to write the code this way. Mathematically, it's the same so I think it should be due to programming reason.. |
---|---|
March 03, 2011 by hevans (NerdKits Staff) |
Hi meeser, I think your factor should be 5000, not 500 if you want to do it that way. I think it will probably work. Humberto |
March 03, 2011 by meeser |
Thank you very much for your help, I thought I did try that but now I've tried it again and it works now... May be I made some other misatkes that time. Both codes work the same now! Thank you meeser |
April 02, 2011 by hariharan |
I did not understand the math you did from lines 23-33. Can you explain it? |
April 02, 2011 by hariharan |
srry, the math from the original code. |
Please log in to post a reply.
Did you know that you can connect digital calipers to a microcontroller? Learn more...
|