Digital Input/Output (I/O) operations are fundamental to microcontroller programming. They allow the microcontroller to interact with the external world through pins that can be set as either inputs or outputs.
// Set pin as output pinMode(LED_PIN, OUTPUT); // Set pin as input pinMode(BUTTON_PIN, INPUT);
// Turn LED on digitalWrite(LED_PIN, HIGH); // Turn LED off digitalWrite(LED_PIN, LOW);
// Read button state
int buttonState = digitalRead(BUTTON_PIN);
if (buttonState == HIGH) {
// Button is pressed
digitalWrite(LED_PIN, HIGH);
}