Circuit that takes a constant hot and send out 1 pulse

Thread Starter

Cam2363

Joined Feb 2, 2018
15
Im working on a project with my raspberry pi and when I push the button, it keeps playing the audio when I want it to play once no matter how long the button is held.

So does anyone know a circuit or just a quick edit in my python script that i can make to do that? I have an arduino that I can use if i need to.

Thanks!
 

noweare

Joined Jun 30, 2017
115
Maybe its me but do you think you can better describe better what you want to happen and what is happening, a circuit diagram and your code would also be useful.
 

Dodgydave

Joined Jun 22, 2012
11,395
Just use a flipflop circuit or a button test routine>> is button pressed y/n > if yes play music, if no goto start...

Use a different input for stop music,. ..
 

Reloadron

Joined Jan 15, 2015
7,908
You may want to look at the Arduino forums or the Raspberry Pi forums. The button involves a state change and you want a loop once. So on a state change loop once and run your code. A Google of "arduino loop once on button pressed" or "Raspberry Pi loop once on button pressed" should get you some usable code samples to modify. I am not a programming type but "think" this should get you where you want to be. Rather than a loop running as long as the button is held you want a single loop once on a state change.

Ron
 

WBahn

Joined Mar 31, 2012
33,076
Im working on a project with my raspberry pi and when I push the button, it keeps playing the audio when I want it to play once no matter how long the button is held.

So does anyone know a circuit or just a quick edit in my python script that i can make to do that? I have an arduino that I can use if i need to.

Thanks!
More detail would be nice, but it sounds like a simple change to your code will accomplish what you want. A number of different ways to do it. One is to use a variable, perhaps called Armed, that you set HI when you want to be sensitive to the system. Then, when you detect a button press, you check if the system is Armed and, if so, you set Armed to LO and play the audio. Any further button press detections will be ignored because the system isn't Armed. Now all you have to do is decide what kind of event(s) will cause you to rearm the system.
 

Thread Starter

Cam2363

Joined Feb 2, 2018
15
More detail would be nice, but it sounds like a simple change to your code will accomplish what you want. A number of different ways to do it. One is to use a variable, perhaps called Armed, that you set HI when you want to be sensitive to the system. Then, when you detect a button press, you check if the system is Armed and, if so, you set Armed to LO and play the audio. Any further button press detections will be ignored because the system isn't Armed. Now all you have to do is decide what kind of event(s) will cause you to rearm the system.
Basically think of it like this, i have a switch and an led, when i flip the switch, i want the led to turn flash one time and turn off until the switch is cycled off and then on again. Thats what im trying to accomplish
 

WBahn

Joined Mar 31, 2012
33,076
So your logic might look something like this:

C:
Armed = TRUE;
while (FOREVER)
{
   if (Armed)
   {
      if (ButtonPressed)
      {
         Armed = FALSE;
         LED = ON;
         delay_ms(1000); // how long you want the LED on
         LED = ON;
      }
   }
   else
   {
      if (!ButtonPressed)
         Armed = TRUE;
   }
   delay_ms(20); // wait a while for switch debounce
}
There are other ways, too. One would be to set time hacks that things happen at. That' lets your loop keep running continuously and not block at every delay event.
 

Thread Starter

Cam2363

Joined Feb 2, 2018
15
So your logic might look something like this:

C:
Armed = TRUE;
while (FOREVER)
{
   if (Armed)
   {
      if (ButtonPressed)
      {
         Armed = FALSE;
         LED = ON;
         delay_ms(1000); // how long you want the LED on
         LED = ON;
      }
   }
   else
   {
      if (!ButtonPressed)
         Armed = TRUE;
   }
   delay_ms(20); // wait a while for switch debounce
}
There are other ways, too. One would be to set time hacks that things happen at. That' lets your loop keep running continuously and not block at every delay event.
Thanks, but I was hoping it would be a simple line in python i needed to add.
 

WBahn

Joined Mar 31, 2012
33,076
Few things are just one line of code -- you can't expect a single line of code to accomplish much in the way of abstract goals. Consider how many different things you had to express to get your objectives across. You want it to play an audio file the when a button is pressed, then you want it to play the audio file only once, then you want it to not do anything else as long as the button remains pressed, but you want it to replay the audio file again after the button is released and then pressed again. Now consider all of the variations that you (or someone else) might have wanted. It's just too much to expect one line of code to accomplish the one variant among many that you are interested in.
 

panic mode

Joined Oct 10, 2011
5,179
what you are looking for is one-shot. this can be done in many different ways (interrupts etc.).
one crude way is to:
wait for button on,
wait for 10ms
wait for button not on
 
Top