Monostable pulse generation

Hi, I'm trying to program the above, without using a 555. I want to do it in software with Arduino if possible.

Closest I have so far is:

//This is an extract 
//"bip" is the tone to generate, outPin is the piezo connection
//"playBip" is triggered by a set of external conditions being met in the main loop.


void playBip(const int outPin) 
{
  unsigned long currentBipmillis = millis();

  if (currentBipmillis - previousBipmillis >= bipmillisInterval)

  {
    previousBipmillis = currentBipmillis;

    if (bipState == 0) {
      bipState = 1;
      bipmillisInterval = 20;
      tone(outPin, 1320);

    } else {
      bipState = 0;
      bipmillisInterval = 500;
      noTone(outPin);
    }
  }
}

This generates the desired tone for the desired duration, but will not accept another input inside the 500ms down time, and will re-trigger itself after 500ms. I want it so that is will generate a 20ms tone once and once only on each trigger, as long as the trigger does not repeat within 20ms, and will remain down indefinitely until the next external trigger.

Thoughts, ideas, etc? Yup, I've looked and pretty much everything I've seen so far resorts to 555's and 7400 series.

I suspect you need to use millis() (or micros() ) to manage the timing without blocking. Have a look at Several Things at a Time

...R

larkin:
Thoughts, ideas, etc?

My idea:

const byte outPin=9; // piezo speaker pin
const unsigned long timeoutDuration=20000L;
boolean triggered;
unsigned long lastTriggerMicros;

void setup() {                
}


void trigger()
{
  if (someConditionIsTrue)
  {
    if (!triggered) // if tone is not already playing
    {
      triggered=true;
      tone(outPin, 1320);
    }
    lastTriggerMicros=micros(); // remember last time of a true trigger condition
  }
}

void timeout()
{
  if (triggered && micros()-lastTriggerMicros>= timeoutDuration)
  {
    triggered=false;
    noTone(outPin);
  }
}

void loop() {
  trigger();
  timeout();
}

jurs, looks good. Will test and let you know. Thank you!