반응형
SMALL

#define BUTTON_PIN      2
#define LED_RED_PIN     4
#define LED_BLUE_PIN    9

volatile int button_state;

void setup()
{
  pinMode(BUTTON_PIN  , INPUT_PULLUP);
  pinMode(LED_RED_PIN , OUTPUT);
  pinMode(LED_BLUE_PIN, OUTPUT);
  attachInterrupt(digitalPinToInterrupt(BUTTON_PIN), buttonInterrupt, CHANGE);
}

void loop()
{
  digitalWrite(LED_BLUE_PIN, HIGH);
  delay(1000);
  digitalWrite(LED_BLUE_PIN, LOW);
  delay(1000);
}

void buttonInterrupt() 
{
  button_state = digitalRead(BUTTON_PIN);

  if (button_state == HIGH) 
  {
    digitalWrite(LED_RED_PIN, LOW);
  }
  if (button_state == LOW) 
  {
    digitalWrite(LED_RED_PIN, HIGH);
  }
}

소스.txt
0.00MB

반응형
LIST

+ Recent posts