quick questions about dira , and outa
mikediv
Posts: 825
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 ???
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
Why should it? The Spin interpreter can't know where you want to loop. The repeat repeats instructions that are indented:
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.
instead of:
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
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
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:
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
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.
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