Nested Objects
Chip Cox
Posts: 73
I am just starting out with Spin so please forgive me if this is an obvious question or is answered elsewhere.
I am playing with the multiple cog object example from the Prop education kit labs.· I have the setup the basic circuit and duplicated it over 3 switches and leds.· I have an array of button cogobjects setup so that I can press a button and a light comes on and blinks like it should.· Each button object calls a blink object to handle the blinking.· Since each button is a separate instance running in it's own cog ( so it can monitor the buttons separately, I thought that each reference to the blink cog_object would be a separate instance as well since it's beng defined in separate instances of button.· But I seem to be getting some cross talk between the objects and don't understand why.
Thanks
I am playing with the multiple cog object example from the Prop education kit labs.· I have the setup the basic circuit and duplicated it over 3 switches and leds.· I have an array of button cogobjects setup so that I can press a button and a light comes on and blinks like it should.· Each button object calls a blink object to handle the blinking.· Since each button is a separate instance running in it's own cog ( so it can monitor the buttons separately, I thought that each reference to the blink cog_object would be a separate instance as well since it's beng defined in separate instances of button.· But I seem to be getting some cross talk between the objects and don't understand why.
Thanks
Comments
The problems start when I try pressing two buttons at once.· Sometimes it works sometimes it doesn't.· The stack is huge so I don't think that's the problem.· When I press two buttons lets say buttons 1 and 3.· Lights 1 and 3 start blinking like they should.· But then if I press button 2, light 3 goes out and it's like the button cog for button 3 dies.·
That's why my original question was around the scope of the objects run by cogs.· I have 3 instances of the button object running in 3 cogs.· So the way I understand it, (put much more simply than it is)·each cog has it's own copy·of the variables to work with.· This keeps any variables in the button cog separate from each other.· If I didn't have separate instances of the objects, the global variables in the object would be common between all three object/cogs.· Thats why I'm wondering about the objects/cogs started from the three instances of button.· Since they seem to have their own address space, do the global variables for the blink objects go into their spaces, or do they all fire against one address space?
I'm sorry I'm doing such a poor job of describing this.
If there's noise or bounce on the pushbutton inputs, the delta will be too short and Blink won't work as you expect it. Put a "sanity" check in ccButton and don't call Blink if the delay is less than 100ms (CLKFREQ/10).