Skip to content

Instantly share code, notes, and snippets.

@adventurist
Last active April 7, 2020 04:21
Show Gist options
  • Save adventurist/c7eb077bb0dc8902d2a1b433dede9216 to your computer and use it in GitHub Desktop.
Save adventurist/c7eb077bb0dc8902d2a1b433dede9216 to your computer and use it in GitHub Desktop.
Arduino circuit with tactile button and 10kohm resistor to control build-in LED
#include <avr/io.h>
#include <stdio.h>
#include <util/delay.h>
int main(void) {
DDRB = 0xFF; // set all pins on PORTB to output
DDRD &= ~(1 << 1); // set pin 2 on PORTD to input
for (;;) {
if ((PIND & (1 << 1))) { // if 2nd bit set on PIND
PORTB |= (1 << 5); // turn on LED
} else {
PORTB &= ~(1 << 5); // turn off LED
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment