Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* Pleasedontcode.com **********
- Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- - Terms and Conditions:
- You have a non-exclusive, revocable, worldwide, royalty-free license
- for personal and commercial use. Attribution is optional; modifications
- are allowed, but you're responsible for code maintenance. We're not
- liable for any loss or damage. For full terms,
- please visit pleasedontcode.com/termsandconditions.
- - Project: "LED Patterns"
- - Source Code NOT compiled for: Arduino Uno
- - Source Code created on: 2024-11-21 11:28:47
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* If the button is not pressed, red LED should be */
- /* blinking for an interval of 0.5s, if the button */
- /* was pressed, both Red and Blue LED should light up */
- /* alternately for an interval of 200ms. */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- #include <EasyButton.h> //https://github.com/evert-arias/EasyButton
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- /***** DEFINITION OF DIGITAL INPUT PINS *****/
- const uint8_t Bhuton_PushButton_PIN_D2 = 2;
- const int redLEDPin = 11; // LED pin for red LED
- const int blueLEDPin = 13; // LED pin for blue LED
- // Define the blinking intervals
- const int redLEDInterval = 500; // 0.5 seconds
- const int blueLEDInterval = 200; // 200 milliseconds
- // Define the state variables
- bool buttonState = false;
- unsigned long previousMillis = 0;
- void setup(void)
- {
- // put your setup code here, to run once:
- pinMode(Bhuton_PushButton_PIN_D2, INPUT_PULLUP);
- // Set the LED pins as outputs
- pinMode(redLEDPin, OUTPUT);
- pinMode(blueLEDPin, OUTPUT);
- }
- void loop(void)
- {
- // put your main code here, to run repeatedly:
- // Read the button state
- buttonState = digitalRead(Bhuton_PushButton_PIN_D2); // Updated to use Bhuton_PushButton_PIN_D2
- // Check if the button is pressed
- if (buttonState == HIGH) {
- // Blink the red and blue LEDs alternately
- unsigned long currentMillis = millis();
- if (currentMillis - previousMillis >= blueLEDInterval) {
- previousMillis = currentMillis;
- // Toggle the state of the LEDs
- digitalWrite(redLEDPin, !digitalRead(redLEDPin));
- digitalWrite(blueLEDPin, !digitalRead(blueLEDPin));
- }
- } else {
- // Blink the red LED only
- unsigned long currentMillis = millis();
- if (currentMillis - previousMillis >= redLEDInterval) {
- previousMillis = currentMillis;
- // Toggle the state of the red LED
- digitalWrite(redLEDPin, !digitalRead(redLEDPin));
- }
- }
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement