Shop OBEX P1 Docs P2 Docs Learn Events
UnderStanding Objects that are in the PE Lab Object v1.1 — Parallax Forums

UnderStanding Objects that are in the PE Lab Object v1.1

sam_sam_samsam_sam_sam Posts: 2,286
edited 2008-07-10 11:26 in Propeller 1
Please help me understand all of what they are talking about in Figure 2
on page 4· Figure [font=Arial,Bold size=1][font=Arial,Bold size=1]2: Calling Methods in Another Object with Dot Notation[/font][/font]
·


·

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··Thanks for any·idea.gif·that you may have and all of your time finding them

·
·
·
·
Sam

Post Edited (sam_sam_sam) : 7/9/2008 6:51:17 PM GMT

Comments

  • StefanL38StefanL38 Posts: 2,292
    edited 2008-07-09 21:57
    hello sam,

    Ok i will try to explain

    The words "method" and "object" have a very different meaning in programming issues
    than what you know from your daily life.

    I will explain on a semi-professional niveau. If you know really nothing about programming this could be still hard to understand
    Then please give a feedback about your programming-skill-Level, and i will adjust the niveau of explaining.
    Or maybe i find an EASY to understand tutorial about object-orientated programming
    "Methods" and obejcts" are common expressions in many programming-languages.
    (BY THE WAY: most programming-turorial are HARD to understand, because most of the authors are experts and have a big blindness about
    difficulties that real beginners have)
    If you want to search for a tutorial yourself. Read 10 sentences and if you don't understand - forget this tutorial and take the next one.
    A really good tutorial is EASY to understand.


    In daily life Aerobic is a "method" to get rid of fat
    and an "object" is somehing inside a modern art museum

    In programming "method" means: a part of code that is a senseful unit

    f.e.: for making an LED blink you need more than one line of code

    pseudocode:
    1.) set IO-PIN to outputmode
    2.) set IO-PIN to 0V initially
    3.) define a loop that will switch the LED on/off X times
    4.) wait some time
    5.) do the switching

    now these lines of code get a name "Blink"

    This is done by the reserved word "PUB" + Name

    PUB Blink(pin, rate, reps)
      dira[noparse][[/noparse]pin]~~
      outa[noparse][[/noparse]pin]~
      repeat reps * 2
        waitcnt(rate/2 + cnt)
        !outa[noparse][[/noparse]pin]
    
    



    The part of the code that has the name "Blink" is called a "method"


    For more complex things like a serial connection to a PC you have MORE than ONE "method"

    To give your code a structure you put together all "methods" (all named codelines PUB + Name)
    that are nescessary for the serial connection in ONE file.

    The serial-code has differents functions as
    - initialize the parameters baudrate, IO-Pins for Tx and Rx
    - send a single byte
    - send a complete string
    - receive a single byte
    - receive a string etc, etc.

    each function will be programmed as a "method"

    PUB Send_Str ....
    ......
    
    PUB Receive_Str ....
    ......
    ....
    
    PUB ....
    ....
    
    
    




    The SUMMARY of ALL "methods" that are nescessary for the serial connection are called an "object"
    All these "methods" are put together in ONE file. Let's say the file is named "serial_connection.spin"
    The code of this file stays the same in every application, because a serial connection is standardized
    (what a big luck !)

    You make a MAIN-file that contains your INDIVIDUAL code

    Now you can implement the functionality "serial connection" by giving the "object" a name

    OBJ
      RS232 : "serial_connection"    '"RS232" is the "objectName" This line of code defines: RS232 is the short name for the contents of the file "serial_connection.spin"
    
    
    



    to access a "method" that is defined inside the file "serial_connection.spin"
    you have to direct the compiler to the right file and the right "method"

    you write

      RS232.Send_Str(StrPtr)   
    
    



    in general terms "objectName-dot-MethodName

    You can imagine this as the PATH to the right part of the code almost like subdirectories

    best regards

    Stefan
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2008-07-10 11:26
    Stefan

    Thank you for explaning it that way

    I was only understanding parts of it but what you have here help me understand·the rest of it

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them

    ·
    ·
    ·
    ·
    Sam

    Post Edited (sam_sam_sam) : 7/10/2008 11:37:12 AM GMT
Sign In or Register to comment.