Shop OBEX P1 Docs P2 Docs Learn Events
Hold down switch to make led light up. — Parallax Forums

Hold down switch to make led light up.

Tony11Tony11 Posts: 41
edited 2010-05-13 12:28 in Propeller 1
Hi

When you push down on pin [noparse][[/noparse]23], it runs the program (pub Right), and repeats it over and over, till you let go of the switch.
Is there A way that I can program it, so when you hold down the switch, it will run to the end of the (pub Right), and stop with all
the (outa[noparse][[/noparse]0..19] := %11111111111111111111) On. Then when you let go of the pin [noparse][[/noparse]23], it will go to off. (outa[noparse][[/noparse]0..19] := %00000000000000000000).

So what I am shooting for. The same way the brake works.

pin held down (22 ON) = All Pin's are on ( outa[noparse][[/noparse]0..19] := %11111111111111111111)


pin (22 off) = ( outa[noparse][[/noparse]0..19] := %0000000000000000)



Thank you.








con 

 _clkmode = xtal1 + pll16x
 _xinfreq = 0_500_000
 
 
pub Kid
          



 repeat


        
    
    if ina  [noparse][[/noparse]22]
   
    
      brake              
       
            
   if ina [noparse][[/noparse]23] 
      
        
           right
  
 
          
pub right
        dira[noparse][[/noparse]0..19] := %11111111111111111111
        outa[noparse][[/noparse]0..19] := %00000000000000000000
        waitcnt(clkfreq/4 + cnt)
        outa[noparse][[/noparse]0..19] := %00000000000000000000
        waitcnt(clkfreq/4 + cnt)
        outa[noparse][[/noparse]0..19] := %10000000000000000000
        waitcnt(clkfreq/4 + cnt)
        outa[noparse][[/noparse]0..19] := %11000000000000000000
        waitcnt(clkfreq/4 + cnt)
        outa[noparse][[/noparse]0..19] := %11100000000000000000
        waitcnt(clkfreq/4 + cnt)
        outa[noparse][[/noparse]0..19] := %11110000000000000000
        waitcnt(clkfreq/4 + cnt)
        outa[noparse][[/noparse]0..19] := %11111000000000000000
        waitcnt(clkfreq/4 + cnt)
        outa[noparse][[/noparse]0..19] := %11111100000000000000
        waitcnt(clkfreq/4 + cnt)
        outa[noparse][[/noparse]0..19] := %11111110000000000000
        waitcnt(clkfreq/4 + cnt)
        outa[noparse][[/noparse]0..19] := %11111111000000000000
        waitcnt(clkfreq/4 + cnt)
        outa[noparse][[/noparse]0..19] := %11111111100000000000
        waitcnt(clkfreq/4 + cnt)
        outa[noparse][[/noparse]0..19] := %11111111110000000000
        waitcnt(clkfreq/4 + cnt)
        outa[noparse][[/noparse]0..19] := %11111111111000000000
        waitcnt(clkfreq/4 + cnt)
        outa[noparse][[/noparse]0..19] := %11111111111100000000
        waitcnt(clkfreq/4 + cnt)
        outa[noparse][[/noparse]0..19] := %11111111111110000000
        waitcnt(clkfreq/4 + cnt)
        outa[noparse][[/noparse]0..19] := %11111111111111000000
        waitcnt(clkfreq/4 + cnt)
        outa[noparse][[/noparse]0..19] := %11111111111111100000
        waitcnt(clkfreq/4 + cnt)
        outa[noparse][[/noparse]0..19] := %11111111111111110000
        waitcnt(clkfreq/4 + cnt)
        outa[noparse][[/noparse]0..19] := %11111111111111111000
        waitcnt(clkfreq/4 + cnt)
        outa[noparse][[/noparse]0..19] := %11111111111111111100
        waitcnt(clkfreq/4 + cnt)
        outa[noparse][[/noparse]0..19] := %11111111111111111110
        waitcnt(clkfreq/4 + cnt)
        outa[noparse][[/noparse]0..19] := %11111111111111111111
     
        
           

pub brake
        dira[noparse][[/noparse]0..19] := %11111111111111111111
        outa[noparse][[/noparse]0..19] := %11111111111111111111
        waitcnt(clkfreq/4 + cnt)
        outa[noparse][[/noparse]0..19] := %00000000000000000000  




Post Edited (Tony11) : 5/13/2010 1:05:05 AM GMT

Comments

  • T ChapT Chap Posts: 4,224
    edited 2010-05-13 01:42
    Just put this at the end

    REPEAT WHILE ina[noparse][[/noparse]23] == 1

    and it will stay there until you let go of the button.
  • MagIO2MagIO2 Posts: 2,243
    edited 2010-05-13 12:28
    And then you should maybe think of a better way to do the same thing using a loop and some boolean operations. What you need is:
    1. a loop
    2. a variable which has the least significant bit set to 1
    3. shift the bit with each iteration
    4. write the bit to the outa

    Of course you have to find the right order ;o) .. and the right operation to 'write' it to the outa ...

    And then compare the longs needed in your first version and in the loop version.

    By the way ... dira is only needed once, as long as you run the code in the same COG. So, I'd move it to the main program in your case and remove it from both functions.

    Post Edited (MagIO2) : 5/13/2010 12:34:47 PM GMT
Sign In or Register to comment.