Created
May 22, 2012 06:01
-
-
Save everblut/2766946 to your computer and use it in GitHub Desktop.
Interrupciones
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int Interruptor = 0; // El interruptor a utilizar sera el 0 es decir el pin digital 2 | |
int ledSalida = 4; // Aqui pondremos un led para ver como funcionan las interrupciones | |
int estado = HIGH; // El estado del led | |
void setup() | |
{ | |
// ponemos en modo output el led | |
pinMode(ledSalida, OUTPUT); | |
digitalWrite(ledSalida, estado); //Lo encendemos | |
//Adjuntamos al interruptor 0 ( pin 2 ) la funcion cambios, cuando suceda un CHANGE | |
attachInterrupt(Interruptor, cambios, CHANGE); | |
} | |
void loop() | |
{ | |
//Simulamos un proceso complicado o largo | |
for (int i = 0; i < 100; i++) | |
{ | |
// "hacemos algo dificil y repetitivo" :P | |
delay(10); | |
} | |
} | |
//Esta seria nuestra funcion critica. | |
void cambios() | |
{ | |
estado = !estado; | |
digitalWrite(ledSalida, estado); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment