Shop OBEX P1 Docs P2 Docs Learn Events
quick questions about dira , and outa — Parallax Forums

quick questions about dira , and outa

mikedivmikediv Posts: 825
edited 2010-03-27 00:04 in Propeller 1
Guys a quick question I know how to blink an LED with the prop but I was wondering if you look at this simple code

pub blink

dira [noparse][[/noparse] 0 ] : = 1
outa [noparse][[/noparse] 0 ] : = 1

outa [noparse][[/noparse] 0 ] : = 0

repeat

I understand how to use delay and make an LED blink but I was wondering why this code does not work I tried it using scope but the output just sits a 0 wouldn't the code start back at outa 1 then cycle down to outa 0 and then back and forth hence a blinking LED ???

Comments

  • pullmollpullmoll Posts: 817
    edited 2010-03-25 18:09
    mikediv said...
    wouldn't the code start back at outa 1 then cycle down to outa 0 and then back and forth hence a blinking LED ???

    Why should it? The Spin interpreter can't know where you want to loop. The repeat repeats instructions that are indented:
        dira[noparse][[/noparse]0] := 1
        repeat
          outa[noparse][[/noparse]0] := 1
          outa[noparse][[/noparse]0] := 0
    
    



    This should toggle port 0 as fast as possible in Spin

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    He died at the console of hunger and thirst.
    Next day he was buried. Face down, nine edge first.
  • JomsJoms Posts: 279
    edited 2010-03-25 18:48
    You could also use:

     
    dira[noparse][[/noparse]0] := 1                   'Set direction of Pin 0
     
    Repeat                         'Repeat following indented instructions
      !outa[noparse][[/noparse]0]                     'toggle pin 0
      waitcnt(clkfreq + cnt)       'wait 1 second
    
    



    instead of:

    dira[noparse][[/noparse]0] := 0                 'Set direction of Pin 0
     
    Repeat                       'Repeat following indented instructions
      outa[noparse][[/noparse]0] := 1               'set pin 0 high
      outa[noparse][[/noparse]0] := 0               'set pin 0 low
      waitcnt(clkfreq + cnt)     'wait 1 second
    
    



    Using the '!' is the toggle function and will just change the output from the current state to the reverse. Also, if it blinks to fast you may have to add a wait command, which I would highly recommend as currently your timing may very. I did put a wait line in my example, but you can change the time or remove it if you wish.

    Post Edited (Joms) : 3/25/2010 6:53:24 PM GMT
  • mikedivmikediv Posts: 825
    edited 2010-03-26 00:34
    No you don't understand Joms thank you for the code but I know how to do it ,, What I am asking and forget the indentation I understand that to ,, I was just showing my question

    Why wont the code

    pub whatever

    dira [noparse][[/noparse] 0 ] : = 1 set P0 to output
    outa [noparse][[/noparse] 0 ] : = 1 set P0 to logic high

    outa [noparse][[/noparse] 0 ] : = 0 set the P0 back to low or 0


    repeat repeat the code from the start

    Why will this not set P0 to blink on and off

    If you leave out the outa [noparse][[/noparse] 0 ] : = 0 line this code will just set P0 to an output of high and then just loop forever
    So why does it not set P0 high and then low and just repeat the whole thing over and over this is what I am asking I know how to do it the way the prop manual and the educational kit show it I am asking why this specific code the way I have it written will not blink P0 on and off

    OH pullmoll I did not see your whole comment I didn't read past the "why should it " part I see reading on that you are saying I did not indent the code properly

    Thank you I just wanted to know why this code would not work and that is exactly the info I was looking for

    Post Edited (mikediv) : 3/26/2010 12:41:20 AM GMT
  • jazzedjazzed Posts: 11,803
    edited 2010-03-26 18:02
    @mikediv,
    Just mentioning incase you forgot ... you need some delay between the outa so your eyes can detect the on/off.
    Joms' first example is a very nice way to do the blink if that's all you want to do. Expanding on your method though:
    pub start
      repeat
        whatever
    
    pub whatever 
      dira [noparse][[/noparse] 0 ] : = 1 'set P0 to output 
      outa [noparse][[/noparse] 0 ] : = 1 'set P0 to logic high 
      waitcnt(clkfreq+cnt)
      outa [noparse][[/noparse] 0 ] : = 0 'set the P0 back to low or 0 
      waitcnt(clkfreq+cnt)
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Short answers?
    Not available since you deserve more information than you requested.

    May the road rise to meet you; may the sun shine on your back.
    May you create something useful, even if it's just a hack.
  • mikedivmikediv Posts: 825
    edited 2010-03-27 00:04
    Jazzed,, guys thank you very much ,,, even after all this time I am still having trouble with the indentation using spin it makes sense once I see it but I still get tripped up sometimes.

    pullmoll showed me where I was going wrong with indent and I really wanted to understand why it would not the work the way I had it my intent was to just see how fast the prop could switch back and forth with no timing and at 100 meg

    OF course I am using an oscilloscope to be honest even with a 5 minute delay my eyes are getting so bad I would probably miss it lol


    as always thank you all very much
Sign In or Register to comment.