Hi AWOL, Hi PaulS,
Thank for your responses. In fact I try to start a sound and in the same time a led ON, when an interruption is detected (Int 1 on pin 3 of arduino board UNO).
This is a part of a small programme to stop a engine of a motorcycle when I put ON the rear speed: the sensor of rear speed is connected on the interrupt 1
In my progam, rear speed is the "Bouton" variable and it is on the interrutp pin .
I follow councils to use volatile variable and delayMicroseconds in a interrupt subroutine.
Thanks for help, and sorry for my bad english, because I am french
I follow councils to use volatile variable and delayMicroseconds in a interrupt subroutine.
You only use volatile if the variable is shared between interrupt and non interrupt contexts.
Your variable "i" was a local and absolutely should not be declared volatile, because of the potential performance hit you could take.
Any variable larger than a byte on the AVR should have further protection to ensure, for instance, the halves of a sixteen bit update are not split across an interrupt.
gglinux:
In fact I try to start a sound and in the same time a led ON, when an interruption is detected (Int 1 on pin 3 of arduino board UNO).
You don't have to stay in the interrupt routine while the sound is made. The ISR could just set a global variable to a value checked by the loop() function and acted upon if the button has been pressed. You still need to consider if you want the code in loop() to stall while the sound is on.
Thank you to all?
I understand the tone instruction does not operate when it is inside an interrupt routine.
I will choose an other solution.
write you later , GF