Shop OBEX P1 Docs P2 Docs Learn Events
Is there A better way to program this. — Parallax Forums

Is there A better way to program this.

Jeff2Jeff2 Posts: 46
edited 2010-05-21 02:53 in Propeller 1
What I need help with is,

If Pin[noparse][[/noparse]23] is pushed fast (toggled, on and off)= it run's the program = (right)
But if Pin[noparse][[/noparse]23] is held at the end of the (right) program, all the led's light up and stay lit till you let go of pin[noparse][[/noparse]23].






What I need to know is, this. Is there A way to program it so when you push (toggled, on and off) pin[noparse][[/noparse]23] it will only run the (right) program.
If you hold down the pin[noparse][[/noparse]23] it will only turn on all led's, till you let go of the pin. Then all led's will be off.


Pin[noparse][[/noparse]23] is off = no led's are on
Pin[noparse][[/noparse]23] pushed = (right)
Pin[noparse][[/noparse]23] held down = all led's on till you let go of Pin[noparse][[/noparse]23]


I hope you get what I am trying to say....











con 

 _clkmode = xtal1 + pll16x
 _xinfreq = 0_500_000
 
 
pub Kid
          



 repeat


   if ina [noparse][[/noparse]23] == 1
      
        
           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
        REPEAT WHILE ina[noparse][[/noparse]23] == 1
        dira[noparse][[/noparse]0..19] := %11111111111111111111
        outa[noparse][[/noparse]0..19] := %11111111111111111111
        waitcnt(clkfreq/4 + cnt)
        outa[noparse][[/noparse]0..19] := %00000000000000000000





Comments

  • Mike GMike G Posts: 2,702
    edited 2010-05-21 00:36
    When the button is pressed enter timed loop. When the loop exists check to see if the button is up or down. If button is up, run PUB right. If the button is still down light the LEDs and repeat until the button is up.

    Post Edited (Mike G) : 5/21/2010 12:43:11 AM GMT
  • Jeff2Jeff2 Posts: 46
    edited 2010-05-21 00:46
    What is A time loop, or where can I look to find on how to program it? I am new at this, that's way I am on here.
  • w8anw8an Posts: 176
    edited 2010-05-21 00:50
    Is this what you mean?

    After running right just keep all the outputs high until input 23 is no longer high.


    
    pub Kid
    
       repeat
           if ina [noparse][[/noparse]23] == 1
               right
               repeat while ina [noparse][[/noparse]23] == 1
                   outa[noparse][[/noparse]0..19] := %11111111111111111111
    
    
    



    ..steve
  • Jeff2Jeff2 Posts: 46
    edited 2010-05-21 01:08
    What I am look for is.

    When the pin[noparse][[/noparse]23] is pushed it run's
    the (right) program.

    If pin[noparse][[/noparse]23] is held it run's the right
    program, then it run's all led's till
    you let go of the pin.


    What I want is. If pin[noparse][[/noparse]23] is held it will
    skip (right) program and just go to
    all led's on till pin is let go.
  • JonnyMacJonnyMac Posts: 9,208
    edited 2010-05-21 01:08
    See attached -- one could argue that it is "better" in the program design and execution.· I whipped it up (quick, but not dirty!) on the demo board so you'll have to change some program constants for your pins, and the dat table that holds the LED pattern for th quick press.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon McPhalen
    Hollywood, CA
  • w8anw8an Posts: 176
    edited 2010-05-21 01:11
    Perhaps this will do that...

    pub Kid
    
       repeat                                      
           if ina [noparse][[/noparse]23] == 1                        'has someone pressed the button?
               waitcnt(clkfreq + cnt)              'the button is pressed, wait a second to decide what to do...
               if ina [noparse][[/noparse]23] == 1                    'the button is still down, just turn on all lamps
                   repeat while ina [noparse][[/noparse]23] == 1
                       outa[noparse][[/noparse]0..19] := %11111111111111111111
               else
                   right                           'the button was released, run the routine
    
    
    
  • Jeff2Jeff2 Posts: 46
    edited 2010-05-21 01:48
    w8an thank you it works good...................


    JonnyMac I have the Propeller Rapid Prototyping Module, I have led's P0 to P19 are the led's and pin[noparse][[/noparse]23] for the input. So I guess I don't know how your program work's to change it to make it work on mine..... I wish I did.............Some day
  • JonnyMacJonnyMac Posts: 9,208
    edited 2010-05-21 02:11
    Oi vey! -- and I'm Irish!· The only way I could have made it easier for you is to come to your house and download the code!· tongue.gif

    All joking aside, you really want to avoid using "magic numbers" for IO pins in your listing; it's absolute bollucks.· Yeah, yeah, I know some Parallax manuals show code this way but those writing such manuals teach programming, they don't put it into embedded products for sale.· I do.· Trust me, when you're trying to redesign a PCB and the connections change the last thing you want to do is go through your code doing line-by-line changes of IO pin #s.· And, no, you can't use global replace because numbers could be valid elsewhere.

    Of course, not having your hardware I can't test the attached code, but given the amount of programming I do I suspect it will work fine.·

    Sorry if I sound harsh; you asked for "better" and then rejected it out-of-hand.· Even if you're not doing programming that goes into products for sale like I do, you want to develop good coding habits so that you can spend more time enjoying your programs than chasing self-induced bugs inside them.· Yes, I'm speaking from experience.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon McPhalen
    Hollywood, CA

    Post Edited (JonnyMac) : 5/21/2010 2:17:57 AM GMT
  • Jeff2Jeff2 Posts: 46
    edited 2010-05-21 02:53
    Hey....Thank You both for your Help,
    and time.
Sign In or Register to comment.