Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <avr/wdt.h> // Include the watchdog timer library
- const int button3Pin = 3; // Pin for Button 3
- const int button4Pin = 4; // Pin for Button 4
- const int button2Pin = 2; // Pin for Button 2
- const int button5Pin = 5; // Pin for Button 5
- const int pin9 = 9; // Pin 9 for the primary output
- const int ledPin = 12; // Pin 12 for the LED
- void setup() {
- pinMode(button3Pin, INPUT_PULLUP); // Button 3
- pinMode(button4Pin, INPUT_PULLUP); // Button 4
- pinMode(button2Pin, INPUT_PULLUP); // Button 2
- pinMode(button5Pin, INPUT_PULLUP); // Button 5
- pinMode(pin9, OUTPUT); // Pin 9 as output
- pinMode(ledPin, OUTPUT); // LED on pin 12 as output
- }
- void loop() {
- // Check if Button 2 is pressed (to reset the Arduino)
- if (digitalRead(button2Pin) == LOW) {
- // Enable the watchdog timer to reset the system
- wdt_enable(WDTO_15MS); // Set a 15ms timeout, enough to reset the Arduino
- while (true) {
- // Infinite loop, the watchdog will reset the Arduino after 15ms
- }
- }
- // Handle Button 5 (pin 5) behavior:
- if (digitalRead(button5Pin) == LOW) {
- // Button 5 is pressed, blink LED on pin 12 every 0.5 seconds
- digitalWrite(pin9, LOW); // Reverse signal
- digitalWrite(ledPin, HIGH);
- delay(250);
- digitalWrite(ledPin, LOW);
- delay(250);
- } else {
- // Button 5 is not pressed, turn off LED and set pin 9 HIGH
- digitalWrite(pin9, HIGH); // Reverse signal
- digitalWrite(ledPin, LOW);
- }
- // If Button 3 is pressed, start the loop to set pin 9 low for 60 seconds, then high for 1 second
- if (digitalRead(button3Pin) == LOW) {
- while (digitalRead(button2Pin) == HIGH) { // Keep looping until Button 2 is pressed
- digitalWrite(pin9, LOW); // Reverse signal
- digitalWrite(ledPin, HIGH); // LED stays ON
- delay(60000); // 60 seconds
- digitalWrite(pin9, HIGH); // Reverse signal
- for (int i = 0; i < 2; i++) { // Blink LED every 0.5 seconds during the 1-second HIGH period
- digitalWrite(ledPin, HIGH);
- delay(250);
- digitalWrite(ledPin, LOW);
- delay(250);
- }
- }
- }
- // If Button 4 is pressed, start the loop to set pin 9 low for 4 seconds, then high for 1 second
- if (digitalRead(button4Pin) == LOW) {
- while (digitalRead(button2Pin) == HIGH) { // Keep looping until Button 2 is pressed
- digitalWrite(pin9, LOW); // Reverse signal
- digitalWrite(ledPin, HIGH); // LED stays ON
- delay(4000); // 4 seconds
- digitalWrite(pin9, HIGH); // Reverse signal
- for (int i = 0; i < 2; i++) { // Blink LED every 0.5 seconds during the 1-second HIGH period
- digitalWrite(ledPin, HIGH);
- delay(250);
- digitalWrite(ledPin, LOW);
- delay(250);
- }
- }
- }
- // If no buttons are pressed, keep the LED off
- digitalWrite(ledPin, LOW);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement