Manual

www.nexusrobot.com Robot Kits manual
17
digitalWrite(ledPin, LOW); // Set a low value to the ledPin
}
}
Arduino button
¾ Interrrupt control
Description
Specifies a function to call when an external interrupt occurs. Replaces any previous function that was
attached to the interrupt. Most Arduino boards have two external interrupts: numbers 0 (on digital pin 2)
and 1 (on digital pin 3). The Arduino Mega has an additional four: numbers 2 (pin 21), 3 (pin 20), 4 (pin
19), and 5 (pin 18).
Sample code
int pin = 13;
volatile int state = LOW;
void setup()
{
pinMode(pin, OUTPUT);
attachInterrupt(0, blink, CHANGE);
}
void loop()
{
digitalWrite(pin, state);
}
void blink()
{
state = !state;
}