Shop OBEX P1 Docs P2 Docs Learn Events
Beginner: Executing a command in a new COG — Parallax Forums

Beginner: Executing a command in a new COG

Hi everyone,

Here's what I want to do: Blink an LED on and off WHILE a sound plays (code is in SPIN). Or, simply continue executing my main program WHILE a sound plays.

I'm using the WAV-Player_DACEngine.spin object file to play the audio. When I execute the statement to play the audio (dac.playWAVFile(string("sample.wav")) for example), it stops the LED in its present state until the audio is finished playing. Once the audio is done playing, only then does my program continue running.

I'm sure the solution is simple and involves running a new cog. But after reading the Propeller Manual and searching the web for examples, I still don't have a good grasp of how to set it all up (I get confused whenever memory, addresses, and longs become involved). I figure creating a new PUB and executing the COGNEW statement is required. If so, how would you define the COGNEW and PUB statements based on my application? Can someone help me figure this out?

Thanks!

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    Launch your blink LED routine into a new COG. :nerd:
  • edited 2016-06-28 18:32
    I've been doing Propeller C for a while now, so my SPIN is a bit rusty (and I don't have an IDE handy to check it) but it should be something simple like
    VAR
      long BlinkStack[6]                'Stack space for Blink cog
      long WavStack[128]             ' Probably a bit large, but I don't know the library. 
    
    
    PUB Main
      cognew(Blink, @BlinkStack)   'Launch blink cog
      cognew(PlayWav, @wavStack) 'Launch wav-playing cog. 
    

    where Blink and PlayWav are the PUB methods that contain the code to start their tasks...

    Edit: Fxied BBCode..
  • DaemonInformaticus: Thanks for the quick feedback. What you wrote is essentially what I guessed in my code (I don't define a separate cog for LED blinking, I just run it in Main). I don't have my hardware yet to see if it works -- I'm just being proactive with my code writing. Once I get my hardware I'll be able to see if it works!
Sign In or Register to comment.