PDA

View Full Version : Is there A better way to program this.

Jeff2
05-21-2010, 07:07 AM
What I need help with is,

If Pin[23] is pushed fast (toggled, on and off)= it run's the program = (right)
But if Pin[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[23].

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

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

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

con

_clkmode = xtal1 + pll16x
_xinfreq = 0_500_000

pub Kid

repeat

if ina [23] == 1

right

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

Mike G
05-21-2010, 07:36 AM
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

Jeff2
05-21-2010, 07:46 AM
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.

w8an
05-21-2010, 07:50 AM
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 [23] == 1
right
repeat while ina [23] == 1
outa[0..19] := %11111111111111111111

..steve

Jeff2
05-21-2010, 08:08 AM
What I am look for is.

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

If pin[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[23] is held it will
skip (right) program and just go to
all led's on till pin is let go.

JonnyMac
05-21-2010, 08:08 AM
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

w8an
05-21-2010, 08:11 AM
Perhaps this will do that...

pub Kid

repeat
if ina [23] == 1 'has someone pressed the button?
waitcnt(clkfreq + cnt) 'the button is pressed, wait a second to decide what to do...
if ina [23] == 1 'the button is still down, just turn on all lamps
repeat while ina [23] == 1
outa[0..19] := %11111111111111111111
else
right 'the button was released, run the routine

Jeff2
05-21-2010, 08:48 AM
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[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

JonnyMac
05-21-2010, 09:11 AM
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!· http://forums.parallax.com/images/smilies/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

Jeff2
05-21-2010, 09:53 AM
Hey....Thank You both for your Help,
and time.