Très bon tutoriel : http://www.lambot.info/interruptions-multiples-sur-arduino/
https://www.pjrc.com/teensy/td_libs_TimerOne.html
https://github.com/PaulStoffregen/TimerOne
https://www.arduino.cc/en/Reference/AttachInterrupt
Exemple :
void setup()
{
Serial.begin(9600);
attachInterrupt(0, playOrPause, RISING);//pin2 -> INT0
//is connected with pin2 of Arduino
}
/*Interrupt service routine*/
void playOrPause()
{
cli();
if(playmode == PLAY)
{
playmode = PAUSE;
sendCommand(CMD_PAUSE,0);
}
else
{
playmode = PLAY;
sendCommand(CMD_PLAY,0);
}
sei();
}
To disable interrupts: cli(); // disable global interrupts and to enable them: sei(); // enable interrupts
http://playground.arduino.cc/Main/AVR
Pour lire les données sur le port série voir l’exemple SerialEvent
Votre commentaire