Shop OBEX P1 Docs P2 Docs Learn Events
Another set of eyes — Parallax Forums

Another set of eyes

bboy8012bboy8012 Posts: 153
edited 2008-02-02 23:55 in Propeller 1
This code right here· I want to take in values from 100 to 220 and send over xbee wirelessly. I get it to send the numbers just fine but included is the start symbol too. My first question is how would I get rid of the "$" after the number is read in to just display the number. My next question is when I add the case statement in it acts all funny. I just want it to compare the whole value. This is to control and ESC for a foam jet using a keyboard (testing phase now until I can implement the joystick with throttle
{{XBeeSpeedControlDemo.spin}}
CON
  _clkmode = xtal1 + pll16x
  _xinfreq = 5_000_000
  pin      = 4
  CR       = 13
VAR
  long idx, cptr
  byte throttle[noparse][[/noparse]256], prevThrottle[noparse][[/noparse]256], bFound, XBbuff[noparse][[/noparse]40], dataIn
OBJ
  ESC   : "ElectriflyESC"
  XBee  : "XBee_Object"
  Term  : "FullDuplexSerial"
  
PUB main
  'Setting up XBee to start recieving on this end
  XBee.start(10, 9, 0, 9600)
  XBee.AT_Init
  XBee.AT_Config(string("ATAP 0"))            ' Set for non-API mode (AT mode)
  XBee.AT_Config(string("ATDL 1"))            ' Set Destination Location to 1
  'Setting up serial port params for debug term
  Term.start(31, 30, 0, 19200)
  waitcnt (1_000_000 * 25 + cnt )
  'Initializing the ESC 
  'ESC.initialize
  'ESC.delay(500)
  readData
PUB readData
  repeat 
    dataIn := XBee.Rx
    if dataIn == "$"                                ' ASCII $ characte    
      bFound := 1
    if bFound == 1
    
      if dataIn == CR
        throttle[noparse][[/noparse]idx] := 0
        idx := 0
        bFound := 0
        Term.str(@throttle[noparse][[/noparse]0])
        Term.tx(10)
        Term.tx(13)
        
      else 
        throttle[noparse][[/noparse]idx] := dataIn
        prevThrottle[noparse][[/noparse]idx] := throttle[noparse][[/noparse]idx]
        idx++
      case @throttle & @prevThrottle
           @throttle > @prevThrottle:
                                      Term.Str(String(10, 13, "Throttle increase: "))
                                      'ESC.throttle(pin, throttle)
           @throttle < @prevThrottle :
                                      Term.Str(String(10, 13, "Throttle decrease: "))
                                      'ESC.throttle(pin, throttle)
           OTHER:
            Term.Str(String(10, 13, "Throttle did not change: "))
            'ESC.throttle(pin, throttle)

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Hunger hurts, starvation works!

Comments

  • deSilvadeSilva Posts: 2,967
    edited 2008-02-02 18:00
    - To get rid of $: Just don't store it in THROTTLE (e.g. add "NEXT" after "bFOUND := 1")
    - CASE is not what you want; read Chapters 3 and 4 of the Manual to learn more about SPIN
    - To compare numerical values you have to convert them into binary format... lots of examples everywhere, as this is a typical beginners problem every week
  • bboy8012bboy8012 Posts: 153
    edited 2008-02-02 20:39
    I have been looking all over the net and could not find anything can u give me an example of converting the numerical values to binady and them comparing them?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Hunger hurts, starvation works!
  • stevenmess2004stevenmess2004 Posts: 1,102
    edited 2008-02-02 21:47
    There are a couple of objects in the object exchange to do this. There should even be some in the library folder that gets installed with prop tool. Have a look at numbers.spin
  • deSilvadeSilva Posts: 2,967
    edited 2008-02-02 23:55
    Well, numbers.fromString might look a little bit alarming smile.gif
    Nevertheles, just use numbers#DEC as format and it might work...
Sign In or Register to comment.