In SX Microcontrollers, SX/B Compiler and SX-Key Tool, Zoot wrote: Mark, I concur with Bean -- if your initial goal is to run the piezo, a few light sensors, and some servos, keep it simple until you need it more complex. You can develop a program that will "appear" to run everything at the same time ("multitask") since the SX is very fast, and 20ms between servos pulses is a lot of time to get other things done. Here is a pseudo-code outline that may help: [code] Beginning: ServoTime = 0? 'if you countdown your servo timer to 0, send a pulse Yes --> send servo pulse(s) to servo pins --> reset ServoTime to equiv. of 20ms to countdown to next pulse No --> ServoTime = ServoTime - 1 LightTime = 0? 'similar to above, but it's how long between light sensor measurements...maybe 10x per second (100ms)? Yes --> get light values into LightValL, LightValR, etc.. --> reset LightTime to evuiv. of 100ms No --> LightTime = LightTime - 1 PiezoTime = 0? 'ditto -- how often should script check for something to send to piezo -- this could be trickier without an ISR 'as you might need to break your sounds into small chunks that fit between 20ms servo pulses Yes --> make a sound, reset PiezoTime No --> PiezoTime = PiezoTime - 1 Middle: LightL > 200 'is light on the left? turn that way Yes --> ServoL = 140, ServoR = 160 LightR > 200 'is light on the right? turn that way? Etc. 'turn right End: GOTO Beginning [/code] So basically your SX rips through the loop at blazing speed, but what actually happens during each loop depends on the state of the timer(s) -- the actual "send to servo" code will only run when 20ms has elapsed, etc. The above is over-simplified, but hopefully it gives the general idea of how you might approach the project. My own style is usually to use just a few counters, updated regularly, and then divide them for my different "tasks", but the individual timers above are easier to read. JonnyMac's ISR routines, and PJV's multi-tasking threads give much tighter timing control and lets you run code virtually in the "background", which could be helpful for your sound work. But understanding the basics of something like the above would help. I've done similar setups on Stamps as well, though they are much slower overall. ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=197473#m197766 Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2007 (http://www.dotNetBB.com)