Passing variables
bboy8012
Posts: 153
How would I pass a variable in one object to another? It seems my way isnt working how I want?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Hunger hurts, starvation works!
''Hyperterm throttle CON _CLKMODE = xtal1 + pll16x _xinfreq = 5_000_000 pin = 4 VAR long stack[noparse][[/noparse]30] byte cog OBJ input : "FullDuplexSerialPlus" esc : "ElectriflyESC" PUB main : okay | pulse input.start(31, 30, 0, 9600) waitcnt(1_000_000 * 100 + cnt) repeat stop input.Str(String("Enter speed: ")) pulse := input.getDec okay := (cog := cognew(esc.Throttle(pulse), @stack) + 1) repeat 2 input.str(String(10, 13)) PUB stop if cog cogstop(cog~ -1)
{{ElectriflyESC.spin This object is for Electrifly SS-35 to initialize and control throttle settings for aircraft. FullBrake = 100 or 1ms FullThrottle = 220 or 2.2ms Calibrating the ESC: apply full brake and pause for 1/2 a second, apply full throttle and pause for another 1/2 second, and lastly bringing it back to full brake and pause for 1/2 a second. }} CON pin = 4 OBJ debug : "FullDuplexSerial" VAR long tC, tHa, t PUB initialize fullBrake 'Fullbrake Delay(500) 'Delay 500 mS fullThrottle 'Fullthrottle Delay(500) 'Delay 500 mS fullBrake 'Fullbrake Delay(500) PRI fullBrake ctra[noparse][[/noparse]30..26] := %00100 'Configure counter A to NCO mode ctra[noparse][[/noparse]8..0] := pin frqa := 1 dira[noparse][[/noparse]4]~~ tC := ((clkfreq/ 100_000) * 2000) ' Set up cycle and high times 20ms tHa := ((clkfreq/ 100_000) * 100) ' 1.0ms pulse t := cnt 'Mark counter time repeat 150 phsa := -tHa ' Set up the pulse t += tC ' Calculate next cycle repeat waitcnt(t) PRI fullThrottle ctra[noparse][[/noparse]30..26] := %00100 'Configure counter A to NCO mode ctra[noparse][[/noparse]8..0] := pin frqa := 1 dira[noparse][[/noparse]4]~~ tC := ((clkfreq/ 100_000) * 2000) ' Set up cycle and high times 20ms tHa := ((clkfreq/ 100_000) * 220) ' 2.2ms pulse t := cnt 'Mark counter time repeat 150 phsa := -tHa ' Set up the pulse t += tC ' Calculate next cycle repeat waitcnt(t) PUB throttle(pulseWidth) debug.start(31, 30, 0, 9600) debug.Str(String(10, 10, 13, "You Entered", 10, 13, "--------------")) debug.Str(String(10, 13, "Speed: ")) debug.Dec(pulseWidth) 'ctra[noparse][[/noparse]30..26] := %00100 'Configure counter A to NCO mode 'ctra[noparse][[/noparse]8..0] := pin 'frqa := 1 'dira[noparse][[/noparse]pin]~~ 'tC := ((clkfreq/ 100_000) * 2000) 'tHa := ((clkfreq/ 100_000) * pulseWidth) 't := cnt 'repeat ' phsa := -tHa 't += tC 'waitcnt (t) PUB Delay(mS) waitcnt((clkfreq / 1000 * mS) + cnt)
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Hunger hurts, starvation works!
Comments
I recall it's not possible to start a method in a different object that way. The method has to be within the object from which it is started.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Hunger hurts, starvation works!