Shop OBEX P1 Docs P2 Docs Learn Events
need object help just not understanding how to use/drivers/objects from downloa — Parallax Forums

need object help just not understanding how to use/drivers/objects from downloa

mikedivmikediv Posts: 825
edited 2009-01-10 03:10 in Propeller 1
Instead of wasting space I just edited my original post....Mike thanks, I am really trying not to ask any more question here·but I just cant figure this out . , I can get the prop to blink differant leds all day what I am having a problem with is using Objects, I do have the class papers even the one on objects but it is not answearing my question I will try and explain a bit better.
Again I am only using the blinking led program as an example for what I am trying do with OBJECTS..

first I wrote an led blinking program
Example ::::::

'' File: LedOnP4.spin
PUB LedOn··································· ' Method declaration
············································
··· dira[noparse][[/noparse]4] := 1···························· ' Set P4 to output
··· outa[noparse][[/noparse]4] := 1···························· ' Set P4 high
··· repeat·································· ' Endless loop prevents program from ending

Ok now I wrote another one and called it mike1 my name plus the number 1 and made this my OBJECT???..

Example ::::::

'' File: mike1.spin
PUB LedOn··································· ' Method declaration
············································
··· dira[noparse][[/noparse]6] := 1···························· ' Set P6 to output
··· outa[noparse][[/noparse]6] := 1···························· ' Set P6 high
··· repeat·································· ' Endless loop prevents program from ending

I did this to try and figure out how to load objects that are available from the·"OBJECT EXCHANGE"

This led code does not matter I am trying to figure out how to call in outside programs and have them WORK.
So here is my third code example Note trying to call the other program as an OBJECT/Driver:::::

'' File: LedOnP4.spin
OBJ· 'Objects Section
· Blink2: "mike1"· 'to see if I can load an object·

PUB LedOn························ ' Method declaration
· Blink2.start ' Just want to load an object to see if it will work
············································
··· dira[noparse][[/noparse]4] := 1···························· ' Set P4 to output
··· outa[noparse][[/noparse]4] := 1···························· ' Set P4 high
··· repeat·································· ' Endless loop prevents program from ending
Again I just want to learn how to use the porgrams in the Object Exchange this is just an example of what I am trying to do so everyone can see the errors I am getting.
For the sake of argument pretend I just wrote code that will say "Hello World. and I want to send it out to a serial terminal
So I would write little porgram but use "FullSerialDuplex" Driver/Object from the Object download section this is what I am trying to learn. I do not know how to USE Objects or get them to work in my main program ..all the driver programs everyone has written and placed there for everyone to use
So my question is how do you use these drivers???? as you can see by my examples of how I am trying to do it its not working so what am I doing wrong thanks guys. P.S I know that they/Object/Drivers can be loaded into a main program I just dont know how to get them to work properly???




Post Edited (mikediv) : 1/10/2009 1:47:16 AM GMT

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-01-10 00:52
    You should work through the Propeller Education Kit tutorials. They will cover the sort of thing you're trying to learn.

    Including "anothblinkprg" in your program simply compiles it with your program. It doesn't execute it.

    There are other errors in what you've posted. What you posted won't compile (at the very least because "d2" is not defined). Please post your actual program and use the [noparse][[/noparse] code ] and [noparse][[/noparse] /code ] tags around it (without the extra spaces) so we can see the formatting clearly.

    Here's a simple multi-blink program. I haven't compiled it, but it should compile and run blinking LEDs on pins 0, 1, and 2 at different rates.
    CON
       _clkmode = xtal1 + pll16x
       _xinfreq = 5_000_000
    
    VAR
       long stack0[noparse][[/noparse]20], stack1[noparse][[/noparse]20]
    
    pub main
       cognew(blink(0, 200, 100), @stack0)   ' Blink pin 0 100 times for 200ms on / 200ms off, then stop cog
       cognew(blink(1, 250, 80), @stack1)   ' Blink pin 1 80 times for 250ms on / 250ms off, then stop cog
       blink(2, 300, 60)   ' Blink pin 2 60 times for 300ms on / 300ms off, then stop cog
    
    pub blink(pin, msTime, reps)
       dira[noparse][[/noparse]pin]~~   ' Make pin an output
       repeat reps   ' Repeat for specified repetititions
          outa[noparse][[/noparse]pin]~   ' Make pin a low (0V)
          waitcnt((clkfreq/1000)*msTime + cnt)   ' Wait specified time
          outa[noparse][[/noparse]pin]~~   ' Make pin a high (3.3V)
          waitcnt((clkfreq/1000)*msTime + cnt)   ' Wait specified time
    
  • JasonDorieJasonDorie Posts: 1,930
    edited 2009-01-10 03:10
    Doing this:

    OBJ 'Objects Section
    Blink2: "mike1" 'to see if I can load an object

    ...isn't actually running anything. It creates an object called Blink2 which contains functions declared in "mike1.spin". Using your above example, it'll have a function called LedOn that turns on an LED and never returns because of the repeat at the end. If you take that out, your program will probably work. Creating an object doesn't change how the functions work - if you want to run one on another cog you need to call cognew on that function, whether it's local (like Mike Green's example) or in a different object. Your 'mike1' file doesn't contain a function called 'start', so the compiler will complain.

    The objects in the object exchange will all have different functions to initialize and interact with them. Some will start their own cogs, while others are just 'function sets' that you call.

    The best way to learn about objects and cogs is to go through the dirt simple example files provided with the Propeller Tool. The Prop takes a little getting used to, but it's not difficult.

    Jason
Sign In or Register to comment.