Spin Refresher: read and store variable values between methods and procedures?
This code illustrates what I am trying to do in a rudimentary simplistic way; but I forgot how to properly address variables. I intentionally left out variable declarations as to not confuse things ... global, and local; as I forgot how to syntax these.
CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 High = 1 Low = 0 P2 = 2 VAR Long stack_0 'Sets up a stack space for a Cog(processor) Long start_temp Long start_A Long start_B Long end_temp Long end_A Long end_B PUB Main CogNew(TimerCog, @stack_0) 'Starts a New Cog repeat ' do other stuff PUB TimerCog | stA, stB, stTemp, enA, enB, enTemp, duration set_pin_to_input(P2) repeat phsa := 0 repeat while phsa < 5_000_000 LogSignal stA := start_A ' do something with values stored in start_A, start_B ... enA := end_A duration = enA - stA ResetLogs PRI LogSignal if ina[P2] == Low and start_temp == 0 ' just dropped low start_temp := phsa if start_A == 0 start_A := start_temp elseif start_B == 0 start_B := start_temp if ina[P2] == High and start_temp <> 0 ' just went high end_temp := end := phsa start_temp := 0 ' reset if end_A == 0 end_A := end_temp elseif end_B == 0 end_B := end_temp PRI ResetLogs start_A := start_B := end_A := end_B := end_temp := start_temp := 0 PUB set_pin_to_input(pin) 'set pin to input dira[pin]~ outa[pin]~
How do I access (read) and save (write) variable values most effectively; locally or globally; and between routines, methods, and objects ... functions?