Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@lettinghenry
lettinghenry / port_manipulation.cpp
Created April 5, 2022 18:20 — forked from nadavmatalon/port_manipulation.cpp
Arduino: Port Manipulation
// DDRD (R/W) pin direction (0 = INPUT / 1 = OUTPUT)
// PORTD (R/W) pin state (INPUT: 0 = LOW / 1 = HIGH | OUTPUT: 0 = PULL-UP DIACTIVATED / 1 = PULL-UP ACTIVATED)
// PIND (R) pin state (INPUT ONLY: 0 = LOW / 1 = HIGH)
// bit(n) // calculates value of n-th bit (returns: 0 / 1)
// bitRead(byteName, n) // gets value of n-th bit of byte (returns: 0 / 1)
// bitSet(byteName, n) // sets value of n-th bit of byte to 1
// bitClear(byteName, n) // sets value of n-th bit of byte to 0
// bitWrite(byteName, n, val) // sets value of n-th bit of byte to 0 or 1