const int ledPin = 13; // Pin connected to the LED
const int clockPin = 12;
const int btnPin = 6;
const int laserPin = 7;
void setup() {
pinMode(btnPin, INPUT);
pinMode(laserPin, INPUT);
pinMode(clockPin, OUTPUT); // Set clock pin as an output
pinMode(ledPin, OUTPUT); // Set the LED pin as an output
Serial.begin(9600); // Initialize serial communication
}
void loop() {
bool btn = digitalRead(btnPin); // Read the state of the button pin
bool laser = digitalRead(laserPin); // Read the state of the laser pin
Serial.print("Button: ");
Serial.print(btn);
Serial.print(" Laser: ");
Serial.println(laser);
clk(btn, laser); // Call the clk function with button and laser states
}
void clk(int btn, int laser){
static bool clockRunning = false; // Track the state of the clock
if(btn == 1 && laser == 1){ // Start the clock if both btn and laser are high
digitalWrite(clockPin, HIGH); // Set the clock pin high
digitalWrite(ledPin, HIGH); // Turn on the LED
delay(500); // Wait for 500 milliseconds
digitalWrite(clockPin, LOW); // Set the clock pin low
digitalWrite(ledPin, LOW); // Turn off the LED
delay(500);// Wait for 500 milliseconds
clockRunning = true; // Update the clock state
}
else if(btn == 1 && laser == 0 && clockRunning){ // Stop the clock if btn is high and laser is low
digitalWrite(clockPin, LOW); // Stop the clock
clockRunning = false; // Update the clock state
}
}
nano:12
nano:11
nano:10
nano:9
nano:8
nano:7
nano:6
nano:5
nano:4
nano:3
nano:2
nano:GND.2
nano:RESET.2
nano:0
nano:1
nano:13
nano:3.3V
nano:AREF
nano:A0
nano:A1
nano:A2
nano:A3
nano:A4
nano:A5
nano:A6
nano:A7
nano:5V
nano:RESET
nano:GND.1
nano:VIN
nano:12.2
nano:5V.2
nano:13.2
nano:11.2
nano:RESET.3
nano:GND.3
r1:1
r1:2
led1:A
led1:C
btn1:1.l
btn1:2.l
btn1:1.r
btn1:2.r
ldr1:VCC
ldr1:GND
ldr1:DO
ldr1:AO