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: Breathing LED
- - Source Code NOT compiled for: Arduino Uno
- - Source Code created on: 2024-09-19 12:41:55
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* i have 4 led and that needs to be breathing LED */
- /* and has sequence of the lights */
- /****** END SYSTEM REQUIREMENTS *****/
- /****** DEFINITION OF LIBRARIES *****/
- #include <Arduino.h> // Include Arduino library for basic functions
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- void updateOutputs();
- void breatheLED(uint8_t pin); // Function to handle breathing effect
- /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
- const uint8_t myLED_LED_PIN_D2 = 2;
- const uint8_t myLED_LED_PIN_D3 = 3;
- const uint8_t myLED_LED_PIN_D4 = 4; // Additional LED pin D4
- const uint8_t myLED_LED_PIN_D5 = 5; // Additional LED pin D5
- /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
- /***** used to store raw data *****/
- bool myLED_LED_PIN_D2_rawData = 0;
- bool myLED_LED_PIN_D3_rawData = 0;
- bool myLED_LED_PIN_D4_rawData = 0; // Additional raw data for LED D4
- bool myLED_LED_PIN_D5_rawData = 0; // Additional raw data for LED D5
- /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
- /***** used to store data after characteristic curve transformation *****/
- float myLED_LED_PIN_D2_phyData = 0.0;
- float myLED_LED_PIN_D3_phyData = 0.0;
- float myLED_LED_PIN_D4_phyData = 0.0; // Additional physical data for LED D4
- float myLED_LED_PIN_D5_phyData = 0.0; // Additional physical data for LED D5
- void setup(void)
- {
- // Initialize the LED pins as outputs
- pinMode(myLED_LED_PIN_D2, OUTPUT);
- pinMode(myLED_LED_PIN_D3, OUTPUT);
- pinMode(myLED_LED_PIN_D4, OUTPUT); // Initialize LED D4
- pinMode(myLED_LED_PIN_D5, OUTPUT); // Initialize LED D5
- }
- void loop(void)
- {
- // Call the breatheLED function for each LED in sequence
- breatheLED(myLED_LED_PIN_D2); // Breathing effect for LED on pin D2
- breatheLED(myLED_LED_PIN_D3); // Breathing effect for LED on pin D3
- breatheLED(myLED_LED_PIN_D4); // Breathing effect for LED on pin D4
- breatheLED(myLED_LED_PIN_D5); // Breathing effect for LED on pin D5
- }
- void updateOutputs()
- {
- digitalWrite(myLED_LED_PIN_D2, myLED_LED_PIN_D2_rawData);
- digitalWrite(myLED_LED_PIN_D3, myLED_LED_PIN_D3_rawData);
- digitalWrite(myLED_LED_PIN_D4, myLED_LED_PIN_D4_rawData); // Update LED D4
- digitalWrite(myLED_LED_PIN_D5, myLED_LED_PIN_D5_rawData); // Update LED D5
- }
- void breatheLED(uint8_t pin)
- {
- // Breathing effect implementation
- for (int brightness = 0; brightness <= 255; brightness++) // Fade in
- {
- analogWrite(pin, brightness); // Set the brightness
- delay(10); // Wait for 10 milliseconds
- }
- for (int brightness = 255; brightness >= 0; brightness--) // Fade out
- {
- analogWrite(pin, brightness); // Set the brightness
- delay(10); // Wait for 10 milliseconds
- }
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement