Passing Variables Question
bgw56
Posts: 6
My questions is as follows:
I have two objects running , one is sensing push button states, the other generating servo pulse timing in a repeat loop.
Is there a way to pass the button state info from the first object into the servo loop of the second while it running for motor control . I've considered passing control info using a pair of I/O pins. One outputting button states and the other being sensed inside the servo pulse timing loop. That seems like the hard way.What's the easy way?
Thanks !
I have two objects running , one is sensing push button states, the other generating servo pulse timing in a repeat loop.
Is there a way to pass the button state info from the first object into the servo loop of the second while it running for motor control . I've considered passing control info using a pair of I/O pins. One outputting button states and the other being sensed inside the servo pulse timing loop. That seems like the hard way.What's the easy way?
Thanks !
Comments
Because it's a single byte / word / long and only one cog changes it (the button one), you don't need to use locks. If you needed more than one storage unit (like an array of words) or if the servo object had to change it, you might have to use locks, but not with the situation you've outlined.
I've succeeded in passing variables between the two objects (button to servo) but never into the timing loop.
Your way sounds like just what I'm looking for.
Can you give me the how-to's of declaring and sharing variables the way you mentioned.
Also, how they can be changed and read by multiple objects.
Thanks
BW
I think I get it now. Just didn't know where to start.
Reading/writing Bytes of Main Memory (Syntax3) Manual P.167
Thanks
BW
After a quick read of Byte and Dat,
Here is some code I tried as a test. I thought it might be possible to share the Dat array between objects.
It works when run in first object alone.
What I need to do in a nutshell : read a button in object 1. Pass that data into a running loop in object 2.
Object 2 could be as simple as stopping a flashing led.
This will not work of course. You should have done what Mike had suggested above! And a lot more...
Mike's suggestion would have lead to the following code; I resort the object tree so it makes sense
All right?
----
Edit: Oh, Mike was 3 minutes faster Well I am a slow typer...
Post Edited (deSilva) : 1/7/2008 12:12:26 AM GMT
BW