Passing variables within methods
Wolfbrother
Posts: 129
Maybe I am up too late but... I'm doing something very odd here. When using this little switch reading routine that JonnyMac helped me with. I'm at the very last part of my odyssey on the propeller design and I wanted to pass a simple flag back from this counter routine to tell me when my mspntr has reached zero or has been forced to zero by pressing the kill switch. This passed flag will be what I use to disable my RFID reader and put the whole device in a low power mode.
Originally the relaycntl was a PRI instead of a PUB, I think I understand that to mean that there aren't global variables passed and any variables used in a PRI to be only available in that method. So, I changed to a PUB, which I think would pass variables. But using the Serial Debugger to output to the screen implies to me that I am never changing this variable. Also in my repeat loop, something happens where I never get a screen print that rlyflag was zero, I think the first time through I should see a zero since I set the variable right before this instruction. Also I commented out the debug statements after the conditional, if flagpass := 1 because the whole program then seems to hang.
I'm sure there is something ridiculously simple I am missing.
Thanks,
Dave
Originally the relaycntl was a PRI instead of a PUB, I think I understand that to mean that there aren't global variables passed and any variables used in a PRI to be only available in that method. So, I changed to a PUB, which I think would pass variables. But using the Serial Debugger to output to the screen implies to me that I am never changing this variable. Also in my repeat loop, something happens where I never get a screen print that rlyflag was zero, I think the first time through I should see a zero since I set the variable right before this instruction. Also I commented out the debug statements after the conditional, if flagpass := 1 because the whole program then seems to hang.
I'm sure there is something ridiculously simple I am missing.
Thanks,
Dave
Comments
And for the record, a private method doesn't affect variable access, it's just not visible outside the object.
Thanks on the PUB/PRI clarification, I'm still getting confused with objects/methods and cogs and passing things around.
switch test with passing2.spin
Thanks. I have tried both of your suggestions and they both work the same. What was interesting to me is that it jumps from 255 ( byte max value) to 0. Then I realized I have an 80Mhz clock and outputting to the screen takes way more than 255 cycles. It does look like this pauses the output for me, so that's what I wanted. I'm not sure which is better form though.
switch test with passing3.spinswitch test with passing4.spin
I thought the expression byte[flagpass] := (long[mspntr] > 0) meant if msnpntr is greater than zero, return a 1
So at that point I was passing back to to rlyflag either a 1 or a 0. But it turns out that it's a -1 or a 0. Which then explains why it would hang up looking for a 1.
So in this case, I prefer the default condition to be a zero and use that to tell my other things (RFID, Tone Generator) to stop running. What I mean to say is that when the rlyflag is nonzero, I can let everything else run. Once it goes to zero, I disable my RFID reader and the tone generator, until the go button is pressed again and the msnpntr is reset.
Thanks,
Dave
switch test with passing5.spin