// Define pin numbers
int ledPin = 13; // Pin number for the LED
int switchPin = 6; // Pin number for the switch
int count = 0; // Variable to store the number of blinks
int lastState = 0; // Variable to store the last state of the switch
// The setup() function runs once when the microcontroller starts
void setup() {
// Set pin modes
pinMode(ledPin, OUTPUT); // Set the LED pin as an output
pinMode(switchPin, INPUT); // Set the switch pin as an input
// Initialize serial communication at a baud rate of 9600
Serial.begin(9600);
}
// The loop() function runs repeatedly
void loop() {
// Read the current state of the switch
int currentState = digitalRead(switchPin);
// Check if the switch has been pressed (rising edge detection)
if (currentState == HIGH && lastState != currentState) {
// Turn on the LED
digitalWrite(ledPin, HIGH);
// Keep the LED on for 1 second
delay(1000);
// Turn off the LED
digitalWrite(ledPin, LOW);
// Keep the LED off for 2 seconds
delay(2000);
// Increment and print the number of blinks
count++;
Serial.println("Number of Blinks:");
Serial.println(count);
}
// Store the current state of the switch to detect changes
lastState = currentState;
}