#include <Servo.h>
// Adjust these pins for your wiring on the Pico
const int LED_PIN = 5; // LED connected to GPIO13
const int SERVO_PIN = 16; // Servo control signal on GPIO9
const int LDR_PIN = 26; // LDR on an ADC pin (GP26 is ADC0 on Pico)
// Threshold for deciding when it's "dark" (Arduino ADC 0..4096)
// ≈ 3125 (out of 4096)
const int THRESHOLD = 3125; // Starting value which is considered darkness
// Set up the LED (digital output) and LDR (analog input)
Servo myservo;
void setup() {
pinMode(LED_PIN, OUTPUT);
// RP2040 ADC is 12-bit; set resolution so analogRead returns 0..4096
analogReadResolution(12);
// Create the servo object
myservo.attach(SERVO_PIN);
// Move servo to main (0°) position
myservo.write(0);
// Optional short delay to let everything initialize
delay(1000);
// For debugging prints analogous to MicroPython's print()
Serial.begin(115200);
}
void loop() {
// Implement the code here:
// Read the LDR sensor value (0 to 4096) and print it for debugging
// Read the LDR value (0..4096)
// If it is dark (val > THRESHOLD):
// - Move the servo to 180 degrees
// - Turn on the LED
// - Wait for 3 seconds
// Otherwise (if there is enough light):
// - Move the servo to 0 degrees
// - Turn off the LED
// Add a small delay to stabilize readings
delay(100);
}