Shop OBEX P1 Docs P2 Docs Learn Events
Variables among cogs, the best way? — Parallax Forums

Variables among cogs, the best way?

RichardFRichardF Posts: 168
edited 2007-06-14 16:00 in Propeller 1
Which is the best way for cog 0 to monitor/use· a value generated in another cog?

method#1 (uses global variable)
VAR
long· stack1[noparse][[/noparse]20]
byte· outside_temp
PUB start
cognew(measure_temp, @stack1)
repeat
· if outside_temp changes
··· updateLCD(outside_temp)
PUB measure_temp
read outside temperature probe
outside_temp := temperature probe reading

Method #2 (uses pointer)
VAR
long· stack1[noparse][[/noparse]20]
byte· outside_temp
PUB start
cognew(measure_temp(@outside_temp), @stack1)
repeat
· if outside_temp changes
··· updateLCD(outside_temp)
PUB measure_temp(temp)
read outside temperature probe
byte[noparse][[/noparse]temp] := temperature probe reading

Thanks,
Richard

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-06-14 16:00
    Method #1 is the most straightforward. If your program structure requires several different objects, then you'll have to use Method #2 because variables in one object are not known in other objects.
Sign In or Register to comment.