Variables among cogs, the best way?
RichardF
Posts: 168
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
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