📅  最后修改于: 2022-03-11 14:58:18.901000             🧑  作者: Mango
void setup() {
DDRD = &= !B00100000; //Set only D5 as INPUT
}
void loop() {
//This is NOT equal to: int value = digitalRead(5);
//Why? Because value = an 8 bit value. For only 1 bit, you need to shif regisers
int value = PIND & B00100000;
//This is equal to int value2 = digitalRead(5);
//Since we read the fifth bit, we need to shift 5 times to the right
int value2 = (PIND >> 5 & B00100000 >> 5);
//In case you want to make an if decision you don't have to shift
//Next line equal to: if(digitalRead(5))
if(PIND & B00100000){
//Add your code...
}
//We can invert the result: Next line equal to: if(!digitalRead(5))
if!(PIND & B00100000){
//Add your code...
}
}