police sound using buzzer and button

We are a group of french student for a project of a buzzer for police use.
We work with arduino for the prototype.
So we want that the programm do:
-when we press one time the button the buzzer do his thing
-than when we press again he stop.
We use the two program (button and buzzer) from the grove of arduino but we don’t know how to code the program.
Please help us.
Thanks from france

Have you tried asking in the French Forum? You may see more timely responses there.

thanks for your answer but the french forum is less active than this one

Do you have the siren effect working?

You need to learn how to make loops. In addition to the main loop, you can make for-loops, [u]while() loops[/u] and do-while loops.

You'll also probably need an [u]if-statement[/u] and some additional [u]logic[/u]. (For example, if the siren is on and the button is pushed, turn it off...)

So we want that the programm do:
-when we press one time the button the buzzer do his thing
-than when we press again he stop.

You want a state change detector on the input button. There is an example program in the IDE under
File -> Examples -> 02.Digital -> StateChangeDetector

thanks for your answer
we find a program for our use of the button but we have to add the two differents program (buzzer and button)

ReverseButton.ino (539 Bytes)

Grove_Buzzer_programme.ino (2.09 KB)

I don't see how any of those programs are related to your problem. The ReverseButton is a particularly silly program. It reads an input and uses the information to set a variable. Then it reads the variable and decides whether to put and buzzer on or off. Why this two stage approach? Simply read the input and put the buzzer on or off.
Like this:-

const int pinButton = 2;
const int pinBuzzer = 4;
int value = 0;

void setup()
    pinMode(pinButton, INPUT);
    pinMode(pinBuzzer, OUTPUT);

void loop()
    if(digitalRead(pinButton)== LOW)
        digitalWrite(pinBuzzer, HIGH);
        digitalWrite(pinBuzzer, LOW);

But as I said this is nothing to do with what you want. You want to detect the state change, that is when the button BECOMES pressed, when it does increment a counter and use the counter value to turn the buzzer on or off.

To do this store the state of the button the last time you read it and compare this to the current time you read it, with a compound if ststement:-

currentRead = digitalRead(pinButton)
if(currentRead== LOW && lastRead == HIGH){
// increment your counter - make sure it only goes from 0 to 1 - if it is at 2 reset it back to 0
// now turn the button on or off depending on the value of the counter

// lastly store the last state of the button foor next time round the loop
lastRead = currentRead;