Propeller Manual

Table Of Contents
2: Spin Language Reference – COGID
COGID
Command: Current cog’s ID number (0-7).
((PUB PRI))
COGID
Returns: The current cog’s ID (0-7).
Explanation
The value returned by
COGID is the ID of the cog that executed the command. Normally, the
actual cog that code is running in does not matter, however, for some objects it might be
important to keep track of it. For example:
PUB StopMyself
'Stop cog this code is running in
cogstop(cogid)
This example method, StopMyself, has one line of code that simply calls COGSTOP with COGID
as the parameter. Since
COGID returns the ID of the cog running that code, this routine causes
the cog to terminate itself.
Propeller Manual v1.1 · Page 75