int ledPin = 13; // Pin connected to the LED
int switchPin = 6; // Pin connected to the switch (unused in the current logic)
int count = 0; // Variable to count the number of LED blinks
void setup() {
pinMode(ledPin, OUTPUT); // Set the LED pin as an output
pinMode(switchPin, INPUT); // Set the switch pin as an input (currently unused)
pinMode(A1, INPUT); // Set analog pin A1 as an input to read analog values
Serial.begin(9600); // Initialize serial communication at 9600 bits per second
}
void loop() {
// Read the analog value from pin A1 and map it to a range of 0 to 1000
int val = map(analogRead(A1), 0, 1023, 0, 1000);
// Check if the mapped analog value is less than 500
if (val < 500) {
digitalWrite(ledPin, HIGH); // Turn the LED on
delay(1000); // Wait for 1 second
digitalWrite(ledPin, LOW); // Turn the LED off
delay(2000); // Wait for 2 seconds
// Print the blink count and the analog value to the Serial Monitor
Serial.println("Number of Blinks:");
Serial.println(++count); // Increment and print the blink count
Serial.println(val); // Print the current analog value
}
}