// Define analog and digital pins
const int analogPin = A0; // AO connected to GP26 (ADC0)
const int digitalPin = 16; // DO connected to GP16
const int ledPin = 15; // LED connected to GP15
void setup() {
// Initialize serial communication
Serial.begin(115200);
// Set digital pin and LED pin as inputs/outputs
pinMode(digitalPin, INPUT);
pinMode(ledPin, OUTPUT);
}
void loop() {
// Read the analog value from the AO pin (range: 0-1023)
int analogValue = analogRead(analogPin);
// Convert analog value to voltage (0 - 3.3V)
float voltage = analogValue * (3.3 / 1023.0);
// Read the digital value from the DO pin
int digitalValue = digitalRead(digitalPin);
// Control the LED based on light level (digital value)
if (digitalValue == HIGH) {
digitalWrite(ledPin, HIGH); // Turn LED on
} else {
digitalWrite(ledPin, LOW); // Turn LED off
}
// Print the analog and digital values
Serial.print("Analog Value: ");
Serial.print(analogValue);
Serial.print("\tVoltage: ");
Serial.print(voltage);
Serial.print(" V\tDigital Value: ");
Serial.println(digitalValue);
delay(1000); // Wait 1 second before the next reading
}