Shop OBEX P1 Docs P2 Docs Learn Events
Passing variables — Parallax Forums

Passing variables

bboy8012bboy8012 Posts: 153
edited 2008-03-19 02:40 in Propeller 1
How would I pass a variable in one object to another? It seems my way isnt working how I want?
''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

  • hippyhippy Posts: 1,981
    edited 2008-03-19 01:54
    bboy8012 said...

    okay := (cog := cognew(esc.Throttle(pulse), @stack) + 1)


    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.
  • bboy8012bboy8012 Posts: 153
    edited 2008-03-19 02:40
    Oh okay, once again I guess I need to stop relying on my java practices for the propeller

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Hunger hurts, starvation works!
Sign In or Register to comment.