Retriggerable One Shot.......
Is there A way I can program, A Retriggerable One Shot, on the Propeller Chip? So I can adjust the RC Time. To turn on A Led, for A given time, and if the input pin is
still pressed (on and off) the led will stay on.
still pressed (on and off) the led will stay on.

Comments
Read push button input pin
if button pressed turn led on
else turn led off
wait retrigger_time
repeat
dira[noparse][[/noparse]6] := 1
dira[noparse][[/noparse]21] := 0
outa[noparse][[/noparse]6] := ina[noparse][[/noparse]21]
waitcnt(clkfreq/4 + cnt)
with the program
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
*Peter*
the hence retriggerable?
I have A Attachment on the circuit.....
Loop:
Read push button input pin
if button pressed timeout = retrigger_time + cnt
led = on
if cnt > timeout
led = off
All you need to do is translate that to spin or pasm.
The problem I have with your question is that on the one hand it is very simple yet on the other it depends how you want it to integrate into your program, there are so many ways and we don't have any details of your program.
I personally would not have a program stop just to handle a button but with so many cogs that might be ok for some.
What I normally do for these types of inputs and timing functions is simply to have a Spin/PASM function running in it's own cog that does nothing else but maintain some software timers, both countdown to zero and countup, The function usually handles specials as well as such things as button inputs and so on. Implementing a one-shot here is nothing more than reloading a countdown timer on a condition, while the counter is non-zero the output is true.
A code snippet for detecting that the button "is" pressed and retriggering the "one-shot" (the functions repeat loop cycles through the soft timers and decrements those that are non-zero)
ifnot ina[noparse][[/noparse]button] ' is button input low? (same as saying "if ina[noparse][[/noparse]button] == 0") timer[noparse][[/noparse]0] := 500 ' reload timer 0 for 500msand a snippet as to how the led would work in the timer function so that it would light while the "one-shot" was active.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
*Peter*
I want to use (Pin23, as the Input switch) and (pin15 of the led)
PUB Led Retriggerabel One Shot
ifnot ina[noparse][[/noparse]23] ' is button input low? (same as saying "if ina[noparse][[/noparse]button] == 0")
timer[noparse][[/noparse]0] := 500 ' reload timer 0 for 500ms
repeat
outa[noparse][[/noparse]15] := !timer[noparse][[/noparse]0] ' turn on active-low led if timer 0 is non-zero
I am bad, I CANT' REMEMBER HOW TO WRITE A EASY PROGRAM........
OBJ
timing : "background"
pub main
background.start ' startup background timing functions
So with this object you should never have to stop and wait for any events as long as you use the various timers all you need to do is load them up with an appropriate delay and then poll them for when they are zero, much like the example in the user processes section of the object itself.
If this looks a bit daunting then maybe you should post your code so I can show you how to incorporate it.
{ background.spin ************************************** BACKGROUND TICK ************************************** Peter Jakacki 2010 ************************************** Purpose: Implement an "interrupt style" background tick which maintains soft-timers and handles other low priority events so as to take the load off the main program from having to time events such as button presses or led blinking etc. Implementation: In this semi-purpose object soft-timers are decremented the equivalent of every 1ms until they are zero. The main program can load these timers and check when they are zero to take appropriate action. User routines may also be added to suit. Resources: cogs: 1 variable: 36 longs program: 29 Limitations: As a high-level function this Spin object cannot be called too fast so the minimum is probably around 1ms. A consequence of trying to go too fast will cause waitcnt to miss the cnt until it cycles around again (~65secs) } con ' these clock constants are normally part of the main program ' but are included here for testing _CLKMODE = XTAL1 + PLL16X _XINFREQ = 5_000_000 clockfreq = ((_CLKMODE - XTAL1) >> 6) * _XINFREQ ' object constants _1mS = clockfreq/1000 'Divisor for 1 mS prescaler = 5 'prescaler from 1ms tick (5ms) timers = 4 'number of soft-timers to support ' user constants button = 0 ' demo button input - active low led = 1 ' demo led output - active low status = 2 ' demo blinking status led var long bgstack[noparse][[/noparse] 32 ] long timer[noparse][[/noparse] timers ] pub start cognew(Background,@bgstack) pri BackGround | i,intv ' user inits outa[noparse][[/noparse] led ]~ ' led off dira[noparse][[/noparse] led ]~~ ' led output ina[noparse][[/noparse] button ]~ ' button input dira[noparse][[/noparse] status ]~~ ' using status led ' longfill(@timer,0,timers) intv := cnt repeat ' synchronized interval wait waitcnt(intv += _1ms*prescaler) ' update soft-timers repeat i from 0 to timers-1 if timer[noparse][[/noparse] i ] timer[noparse][[/noparse] i ] -= prescaler ' user processes etc ifnot ina[noparse][[/noparse] button ] ' is button input low? (same as saying "if ina[noparse][[/noparse] button ] == 0") timer[noparse][[/noparse] 0 ] := 500 ' reload timer 0 for 500ms outa[noparse][[/noparse] led ] := !timer[noparse][[/noparse] 0 ] ' activate led while timer0 is active ifnot timer[noparse][[/noparse] 1 ] ' status led !outa[noparse][[/noparse]status] timer[noparse][[/noparse] 1 ] := 200 ' this timer could be loaded from the main program instead▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
*Peter*
http://forums.parallax.com/showthread.php?p=617192
PS..Stop with the capital "A", it's annoying.
PPS..If you keep the thread in one place it might get answered more often.
to the Program, so I can adjust the Time.
con _clkmode = xtal1 + pll16x _xinfreq = 0_500_000 pub Kid 'dira[noparse][[/noparse]0..19]~~ repeat if ina [noparse][[/noparse]22] ((((the input one pin22, need's to be Retriggerabel One Shot, how does the progarm have to look?)))))) right if ina [noparse][[/noparse]23] left 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] := %00000000010000000000 waitcnt(clkfreq/4 + cnt) outa[noparse][[/noparse]0..19] := %00000000110000000000 waitcnt(clkfreq/4 + cnt) outa[noparse][[/noparse]0..19] := %00000001110000000000 waitcnt(clkfreq/4 + cnt) outa[noparse][[/noparse]0..19] := %00000011110000000000 waitcnt(clkfreq/4 + cnt) outa[noparse][[/noparse]0..19] := %00000111110000000000 waitcnt(clkfreq/4 + cnt) outa[noparse][[/noparse]0..19] := %00001111110000000000 waitcnt(clkfreq/4 + cnt) pub left dira[noparse][[/noparse]0..19] := %11111111111111111111 outa[noparse][[/noparse]0..19] := %00000000000000000000 waitcnt(clkfreq/4 + cnt) outa[noparse][[/noparse]0..19] := %00000000001000000000 waitcnt(clkfreq/4 + cnt) outa[noparse][[/noparse]0..19] := %00000000001100000000 waitcnt(clkfreq/4 + cnt) outa[noparse][[/noparse]0..19] := %00000000001110000000 waitcnt(clkfreq/4 + cnt) outa[noparse][[/noparse]0..19] := %00000000001111000000 waitcnt(clkfreq/4 + cnt) outa[noparse][[/noparse]0..19] := %00000000001111100000