arduino interrupt

 

 

 

 

int pinInterrupt = 2; // Connect the pin of the interrupt signal 
 
void onChange () 
{ 
  Serial.println ("Key go"); 
   if (digitalRead (pinInterrupt) == LOW) 
      Serial.println ("Key Down"); 
   else 
      Serial. println ("Key UP"); 
} 
 
void setup () 
{ 
   Serial.begin (9600); // Open serial port 
 
   pinMode (pinInterrupt, INPUT); // Set the pin as input 
   
   // Enable interrupt pin, the interrupt service program onChange (), monitor pin change 
   attachInterrupt (digitalPinToInterrupt (pinInterrupt), onChange, CHANGE); 
  // attachInterrupt (pinInterrupt, onChange, RISING); 
   / * 
   LOW When the pin is low, trigger the interrupt 
   CHANGE when the pin level When a change occurs, the interrupt 
   RISING is triggered. When the pin changes from low to high, the interrupt 
   FALLING is triggered. When the pin changes from high to low, the interrupt is triggered.
   * / 

} 
 
void loop () 
{ 
  // Simulate long-running processes or complex tasks. 
  for (int i = 0; i <100; i ++) 
  { 
    // Do nothing, wait 10ms 
    delay (10); 
  } 
}

  

Guess you like

Origin www.cnblogs.com/kekeoutlook/p/12709947.html