Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
/********* 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
//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 */
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)