Advertisement
pleasedontcode

Breathing LED rev_01

Sep 19th, 2024
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: Breathing LED
  13.     - Source Code NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2024-09-19 12:41:55
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* i have 4 led and that needs to be breathing LED */
  21.     /* and has sequence of the lights */
  22. /****** END SYSTEM REQUIREMENTS *****/
  23.  
  24. /****** DEFINITION OF LIBRARIES *****/
  25. #include <Arduino.h> // Include Arduino library for basic functions
  26.  
  27. /****** FUNCTION PROTOTYPES *****/
  28. void setup(void);
  29. void loop(void);
  30. void updateOutputs();
  31. void breatheLED(uint8_t pin); // Function to handle breathing effect
  32.  
  33. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  34. const uint8_t myLED_LED_PIN_D2 = 2;
  35. const uint8_t myLED_LED_PIN_D3 = 3;
  36. const uint8_t myLED_LED_PIN_D4 = 4; // Additional LED pin D4
  37. const uint8_t myLED_LED_PIN_D5 = 5; // Additional LED pin D5
  38.  
  39. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  40. /***** used to store raw data *****/
  41. bool myLED_LED_PIN_D2_rawData = 0;
  42. bool myLED_LED_PIN_D3_rawData = 0;
  43. bool myLED_LED_PIN_D4_rawData = 0; // Additional raw data for LED D4
  44. bool myLED_LED_PIN_D5_rawData = 0; // Additional raw data for LED D5
  45.  
  46. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  47. /***** used to store data after characteristic curve transformation *****/
  48. float myLED_LED_PIN_D2_phyData = 0.0;
  49. float myLED_LED_PIN_D3_phyData = 0.0;
  50. float myLED_LED_PIN_D4_phyData = 0.0; // Additional physical data for LED D4
  51. float myLED_LED_PIN_D5_phyData = 0.0; // Additional physical data for LED D5
  52.  
  53. void setup(void)
  54. {
  55.     // Initialize the LED pins as outputs
  56.     pinMode(myLED_LED_PIN_D2, OUTPUT);
  57.     pinMode(myLED_LED_PIN_D3, OUTPUT);
  58.     pinMode(myLED_LED_PIN_D4, OUTPUT); // Initialize LED D4
  59.     pinMode(myLED_LED_PIN_D5, OUTPUT); // Initialize LED D5
  60. }
  61.  
  62. void loop(void)
  63. {
  64.     // Call the breatheLED function for each LED in sequence
  65.     breatheLED(myLED_LED_PIN_D2); // Breathing effect for LED on pin D2
  66.     breatheLED(myLED_LED_PIN_D3); // Breathing effect for LED on pin D3
  67.     breatheLED(myLED_LED_PIN_D4); // Breathing effect for LED on pin D4
  68.     breatheLED(myLED_LED_PIN_D5); // Breathing effect for LED on pin D5
  69. }
  70.  
  71. void updateOutputs()
  72. {
  73.     digitalWrite(myLED_LED_PIN_D2, myLED_LED_PIN_D2_rawData);
  74.     digitalWrite(myLED_LED_PIN_D3, myLED_LED_PIN_D3_rawData);
  75.     digitalWrite(myLED_LED_PIN_D4, myLED_LED_PIN_D4_rawData); // Update LED D4
  76.     digitalWrite(myLED_LED_PIN_D5, myLED_LED_PIN_D5_rawData); // Update LED D5
  77. }
  78.  
  79. void breatheLED(uint8_t pin)
  80. {
  81.     // Breathing effect implementation
  82.     for (int brightness = 0; brightness <= 255; brightness++) // Fade in
  83.     {
  84.         analogWrite(pin, brightness); // Set the brightness
  85.         delay(10); // Wait for 10 milliseconds
  86.     }
  87.     for (int brightness = 255; brightness >= 0; brightness--) // Fade out
  88.     {
  89.         analogWrite(pin, brightness); // Set the brightness
  90.         delay(10); // Wait for 10 milliseconds
  91.     }
  92. }
  93.  
  94. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement