Implementing a multivibrator function with python

J

JL

I am trying to implement a multivibrator function with python. This is how it works;

- An trigger event happens
- Upon receiving the event, a variable goes high for 5secs, then go low.
- If the event happens again before the 5secs expire, the high duration will be extended by another 5 secs. This works like a retriggerable multivibrator for those who are into electronics.

Is there some sample code for this problem or can someone point me to using the right library for this feature?

Thank you very much.
 
D

Dave Angel

- If the event happens again before the 5secs expire, the high
duration will be extended by another 5 secs. This works like a
retriggerable multivibrator for those who are into electronics.

More precisely a retriggerable monostable multivibrator.

The question makes little sense unless you're running in an event
driven environment, such as a gui. Name the environment and somebody
can probably help.
 
T

Terry Reedy

I am trying to implement a multivibrator function with python. This is how it works;

- An trigger event happens
- Upon receiving the event, a variable goes high for 5secs, then go low.
- If the event happens again before the 5secs expire, the high duration will be extended by another 5 secs. This works like a retriggerable multivibrator for those who are into electronics.

Is there some sample code for this problem or can someone point me to using the right library for this feature?

Python 3.4 will have a new asyncio package that includes an event loop
module. It will be in the forthcoming 3.4.b0 release; it might be in
3.4.a4 but I have not installed that yet. In any case, I believe it
should make the above easy.
 
A

Antoon Pardon

Op 11-11-13 10:41, JL schreef:
I am trying to implement a multivibrator function with python. This is how it works;

- An trigger event happens
- Upon receiving the event, a variable goes high for 5secs, then go low.
- If the event happens again before the 5secs expire, the high duration will be extended by another 5 secs. This works like a retriggerable multivibrator for those who are into electronics.

Is there some sample code for this problem or can someone point me to using the right library for this feature?

Thank you very much.
The problem is that it depnds on the kind of trigger event. Is it a signal?
Is it a character that arrives through a pipe or socket?

I would take a look at the signal module and see if it can get you started.
 
A

Antoon Pardon

Op 12-11-13 15:44, JL schreef:
I am actually running python on raspberry pi. The trigger event is a button-press.

That doesn't help. What does that button-press cause in terms of the OS. Does
it cause a signal? Does it produce a number of bytes that can be read from
some file like object? Something else?

This is not python specific, the answer to those questions is needed no matter
what language you use to implement your function.
 
J

Joel Goldstick

Op 12-11-13 15:44, JL schreef:

That doesn't help. What does that button-press cause in terms of the OS. Does
it cause a signal? Does it produce a number of bytes that can be read from
some file like object? Something else?

This is not python specific, the answer to those questions is needed no matter
what language you use to implement your function.

This interests me because I started out in Electrical engineering
school in college. I'm intrigued by raspberry pi. I bet you would
find specific answers reading about how the hardware works. Does
Raspberry pi come with push buttons that are connected to some io
ports or a usb port or a keyboard or?

If there is no physical switch, one of the gui frameworks for python
certainly will have hooks to invoke code when a (virtual) button is
pressed.

Maybe find a Raspberry pi newsgroup?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top