This program shows how to set a pin as output and turn it on, then read another pin as input.
#include <stdio.h>
// Simulated GPIO functions for demo
int gpio_pins[10] = {0};
void GPIO_SetPinOutput(int pinNumber) {
// In real embedded, this sets pin mode to output
printf("Pin %d set as output\n", pinNumber);
}
void GPIO_WritePin(int pinNumber, int value) {
gpio_pins[pinNumber] = value;
printf("Pin %d output set to %d\n", pinNumber, value);
}
int GPIO_ReadPinInput(int pinNumber) {
// In real embedded, this reads pin state
return gpio_pins[pinNumber];
}
int main() {
GPIO_SetPinOutput(1); // Set pin 1 as output
GPIO_WritePin(1, 1); // Turn on pin 1 (like turning on LED)
int sensorValue = GPIO_ReadPinInput(2); // Read pin 2 input
printf("Sensor value on pin 2 is %d\n", sensorValue);
return 0;
}