uint8_t input_pins = B00011010;
void setup() {
Serial.begin(9600);
print_led_states(); // พิมพ์สถานะเริ่มต้น
check_bit_6();
}
void loop() {
}
// ฟังก์ชันช่วยแสดงผลเป็นเลขฐานสอง
void print_led_states() {
Serial.print("LED States: ");
// พิมพ์เลขฐานสอง 8 หลัก (มี 0 นำหน้าถ้าจำเป็น)
for (int i = 7; i >= 0; i--) {
Serial.print(bitRead(input_pins, i)); // bitRead() เป็นฟังก์ชันใน Arduino ช่วยให้อ่านค่าง่ายขึ้น
}
Serial.println();
}
void check_bit_6(){
if (input_pins &= (1 << 6)){
Serial.println("bit 6 is 1");
}else{
Serial.println("bit 6 is 0");
}
}
// bitRead(value, bit_position) ใน Arduino ก็คือการทำ (value >> bit_position) & 1