Shop OBEX P1 Docs P2 Docs Learn Events
Help stopping a cog using a pushbutton — Parallax Forums

Help stopping a cog using a pushbutton

PacoPaco Posts: 2
edited 2010-10-21 08:22 in Propeller 1
Hello everyone,
I am using the propeller chip to display some info on a LCD screen. I get data from sensors and am able to display some of it on the LCD. Here is my problem, I have a Menu screen displayed on the 4x20 LCD and when I push a button (pin 8) I create a new cog to run another object. I want to be able to run the new object in a new cog and then, whenever I push any one of 3 buttons (pin 9, 10, or 11), the cog should stop and return to the main menu object.

Here is the code I have to launch the new cog:

if ina[8] == 1
screen.cls
screen.str(string("Auto Mode", 13))
thedim := (cognew(dimmer.Main, @stack) + 1)

if ina[9] == 1 or ina[10] == 1 or ina[11] == 1
cogstop(thedim)


Will this work? I tried several ways and sometime it seems like it stops the cog originally running and keeps the new cog running. Any suggestions would be great, thanks in advance.

Comments

  • Bobb FwedBobb Fwed Posts: 1,119
    edited 2010-10-20 15:10
    Read mpark's post.

    A full copy of your code may be helpful here. It seems like a simple question, but it all depends on how you have your code setup. Also, putting code into [code] boxes would be nice, so we can see indention.

    One easy way to possibly do what you are trying for, is if the same object is called for each of the three buttons (that's what it looks like in your above code), add a "stop" method that automatically gets called when a "start" method is called.
  • mparkmpark Posts: 1,305
    edited 2010-10-21 08:22
    Either remove "+ 1" from this line
    thedim := (cognew(dimmer.Main, @stack) + 1)
                                           ^^^
    
    or add "- 1" to this line
    cogstop(thedim)
                  ^
    
Sign In or Register to comment.