const int start = 2, alaram = 5, oneMin = 0;
int buttonState = 0; // Variable to store the button state
// Timer variables
volatile unsigned long timerStart = 0;
unsigned long timerDuration = 0;//6000;//0; // 1 minute in milliseconds
void setup() {
pinMode(start, INPUT_PULLUP);
pinMode(oneMin, INPUT_PULLUP);
pinMode(alaram, OUTPUT);
}
void loop() {
if(digitalRead(oneMin)) timerDuration = 180000;
else timerDuration = 60000;
// Check button state
if (digitalRead(start))
// Button pressed, update timer start time
timerStart = millis();
// Check if timer duration has elapsed
if (millis() - timerStart >= timerDuration) {
// Timer completed, start buzzer
digitalWrite(alaram, HIGH);
} else {
// Timer running, keep buzzer off
digitalWrite(alaram, LOW);
}
}
// write ATtiny85 code in arduino to start timer if button 1 is pushed after completion of 1min buzer starts
// #include <avr/io.h>
// // Define button and buzzer pins
// const int buttonPin = 2;
// const int buzzerPin = 3;
// // Timer variables
// volatile unsigned long timerStart = 0;
// const unsigned long timerDuration = 60000; // 1 minute in milliseconds
// void setup() {
// // Set button pin as input and enable pull-up resistor
// DDRB &= ~(1 << buttonPin);
// PORTB |= (1 << buttonPin);
// // Set buzzer pin as output
// DDRB |= (1 << buzzerPin);
// // Start timer counter
// TCNT0 = 0;
// TCCR0B = (1 << CS01); // Start timer with prescaler 8
// }
// void loop() {
// // Check button state
// if (!(PINB & (1 << buttonPin))) {
// // Button pressed, update timer start time
// timerStart = millis();
// }
// // Check if timer duration has elapsed
// if (millis() - timerStart >= timerDuration) {
// // Timer completed, start buzzer
// digitalWrite(buzzerPin, HIGH);
// } else {
// // Timer running, keep buzzer off
// digitalWrite(buzzerPin, LOW);
// }
// }