Arduino Nano, start/stop button for engine sound and a servo controlled by potentiometer. The original code is from TheDIYGUY999, link in attachment.
I tried to customize the code just for this particular test where I can run the sound engine and in the same time control the servo. The problem I can see is the interrupt, even using dedicated ServoTimer2.h library, the sound is working but not the servo, so do I have another option here or I hit a limitation? Thanks
Test servo and sound05.ino (11.2 KB)
First of all, why do you rename your sketch to something that can not be opened by the IDE ?!! Great you give it a meaningful name, but don’t put any spaces in it. If you want people to help the best is to post the sketch within </> code-tags, if the size of the sketch gets you in trouble with the 9000 chars rule, remove white lines and meaningless comments until it does fit, or spread it out over 2 posts.
so do I have another option here or I hit a limitation? Thanks
Well i suspect that the PCM playing is using something that the Servo library wants to use, but there is a simple solution that you could try, which is sending the pulse manually every 20ms (or more, most servos work fine with a pulse up to every 100ms) The library is probably using a timer to get trigger that process, but you can use a simple ‘elapsed-time’ check, and hold up the program until the pulse is completed. The audio playing is interrupt based, so that should not be affected.
This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.