Help with a program capable of producing two pulses lasting 1 second each

Hi folks,
Trying to build a circuit to produce only TWO POSITIVE PULSES that will last 1 SECOND each, separated each other 1 SECOND on pin #12. Also, to produce only ONE POSITIVE PULSE that will last 1 SECOND on pin #13. BOTH ACTIONS will take place if pin#2 has a push button that is pushed and/or released (with a solid toggle either HIGH or LOW).
I tried the Edge Detection sketch, but never achieved what was planned.
Could anybody help me with this nightmare?
Thanks in advance! cc

What is the issue - creating the two pulses or detecting the switch has been pressed? Not sure what your real issue is from the description.

Attach your code using the </> icon on the left side of the posting menu.
Put your sketch between the code tags [code][/code]

Hi, thanks for the reply.

I need three things to happen when a toggle switch on pin #2 closes and opens:

  1. Produce TWO "high" pulses lasting 1 second each on pin #12.
  2. Delay ONE second.
  3. Produce ONE "high" pulse lasting 1 second on pin#13.

All three in that order, with one toggle of a switch, so, It will happen every time the switch is ON and every time the switch is OFF.

As previously said, I have tried the "Edge detector sketch" and modified some variable, but it did not work.
Thank you! cc

We will help you with coding but we won't write the sketch for you.

If you have tried to write some code, show us it.

.

Look at the demo Several Things at a Time. The code that causes the LEDs to flash could be adapted to produce your 1 second pulses.

...R

cachimbon:
I tried the Edge Detection sketch, but never achieved what was planned.
Could anybody help me with this nightmare?
Thanks in advance! cc

Sounds like homework to me. Please post what you attempted but "never achieved".

The purpose of assignments like this is for you to learn something. If we do it, we learn something but you don't.

Dude, show us what you got, AND tell us what are you really trying to do!

Like Nick suggested, this sounds like some lame school assignment to me. I'm not trying to dismiss what the others said (or your teacher ... well, maybe a bit), but just go ahead and use the 'evil' delay() function if this is really what you want. Like this:

// Demonstrates several digital pin functions
boolean lastToggleState;

void setup() {
  pinMode(13, OUTPUT); // the builtin LED
  pinMode(12, OUTPUT); // pin12 -- led -- 330 ohm resistor -- GND
  pinMode(2, INPUT_PULLUP); // pin2 -- switch -- GND

  lastToggleState = digitalRead(2);
}

void loop() {
  if (digitalRead(2) != lastToggleState) {
    digitalWrite(12, HIGH);  // turn the LED 12 on
    delay(1000);             // wait a sec
    digitalWrite(12, LOW);   // turn the LED 12 off
    delay(1000);             // wait a sec
    digitalWrite(12, HIGH);  // turn the LED 12 on
    delay(1000);             // wait a sec
    digitalWrite(12, LOW);   // turn the LED 12 off
    delay(1000);             // wait a sec
    digitalWrite(13, HIGH);  // turn the LED 13 on
    delay(1000);             // wait a sec
    digitalWrite(13, LOW);   // turn the LED 13 off
    lastToggleState = digitalRead(2);
  }
}

See - it does what you said. But you may notice the switch is inactive for 5 seconds at a time - thanks delay.

Now you need to start thinking about what your program is doing. If that's not happening, look into an easier major.