RuiViana

Learn_Interrupt

Aug 11th, 2016
155
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int led = 13;
  2. int x = 10;
  3. byte jacare;
  4. //----------------------------------
  5. void emergencia()
  6. {
  7.   jacare = 1;
  8.   Serial.println("Emergencia");
  9. }
  10. //----------------------------------
  11. void setup()
  12. {
  13.   pinMode(led, OUTPUT);
  14.   pinMode(2, INPUT_PULLUP);
  15.   digitalWrite(2, 1);
  16.   Serial.begin(9600);
  17.   attachInterrupt(0, emergencia, FALLING);
  18. }
  19. //-----------------------------------
  20. void loop() {
  21.   for (int i = 0; i < x; i++)
  22.   {
  23.     Serial.println(i);
  24.     delay(500);
  25.     if (jacare == 1)
  26.     {
  27.       digitalWrite(led, LOW);
  28.       delay(500);
  29.       digitalWrite(led, HIGH);
  30.       delay(500);
  31.       digitalWrite(led, LOW);
  32.       delay(500);
  33.       digitalWrite(led, HIGH);
  34.       delay(500);
  35.  
  36.       jacare = 0;
  37.     }
  38.   }
  39. }
RAW Paste Data