Skip to content

Instantly share code, notes, and snippets.

@JeffersGlass
Created July 12, 2020 22:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JeffersGlass/4570f0a24cfaa5683aec3a3bb9d1b916 to your computer and use it in GitHub Desktop.
Save JeffersGlass/4570f0a24cfaa5683aec3a3bb9d1b916 to your computer and use it in GitHub Desktop.
const int button = PORTD5;
const int led = PORTD2;
void setup() {
// put your setup code here, to run once:
DDRD = _BV(led); //Configure LED for output, button is input
PORTD = _BV(button); //Enable button on button pin
PCICR = _BV(PCIE0); //Enable Pin Change Interrupt 0
PCMSK0 = _BV(PCINT5); //Mask out all other bits besides pin 5 (button)
}
void loop() {
}
ISR(PCINT0_vect){ //When button changes state,
PORTD ^= _BV(led); //Toggle LED
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment