Advertisement
pleasedontcode

RGB LED Control rev_02

May 2nd, 2024
580
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: RGB LED Control
  13.     - Source Code NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2024-05-02 09:36:55
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* The system control an RGB LED and a piezo using */
  21.     /* Arduino UNO.A short press on the push button (less */
  22.     /* than 300ms) shall change the RGB status in a */
  23.     /* sequence of: dimmed, red, green, blue. A long */
  24.     /* press and release (more than 500ms) shall trigger */
  25.     /* the piezo. */
  26. /****** END SYSTEM REQUIREMENTS *****/
  27.  
  28. /****** DEFINITION OF LIBRARIES *****/
  29. #include <EasyButton.h> //https://github.com/evert-arias/EasyButton
  30.  
  31. /****** FUNCTION PROTOTYPES *****/
  32. void setup(void);
  33. void loop(void);
  34. void updateOutputs(void);
  35.  
  36. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  37. const uint8_t myButton_PushButton_PIN_D2 = 2;
  38.  
  39. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  40. const uint8_t myRgb_LEDRGB_Red_PIN_D4 = 4;
  41. const uint8_t myRgb_LEDRGB_Green_PIN_D5 = 5;
  42. const uint8_t myRgb_LEDRGB_Blue_PIN_D6 = 6;
  43.  
  44. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  45. /***** used to store raw data *****/
  46. bool myRgb_LEDRGB_Red_PIN_D4_rawData = 0;
  47. bool myRgb_LEDRGB_Green_PIN_D5_rawData = 0;
  48. bool myRgb_LEDRGB_Blue_PIN_D6_rawData = 0;
  49.  
  50. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  51. /***** used to store data after characteristic curve transformation *****/
  52. float myRgb_LEDRGB_Red_PIN_D4_phyData = 0.0;
  53. float myRgb_LEDRGB_Green_PIN_D5_phyData = 0.0;
  54. float myRgb_LEDRGB_Blue_PIN_D6_phyData = 0.0;
  55.  
  56. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  57.  
  58. // Instance of the button.
  59. EasyButton button(myButton_PushButton_PIN_D2);
  60.  
  61. void setup(void)
  62. {
  63.     // put your setup code here, to run once:
  64.  
  65.     pinMode(myButton_PushButton_PIN_D2, INPUT_PULLUP);
  66.  
  67.     pinMode(myRgb_LEDRGB_Red_PIN_D4, OUTPUT);
  68.     pinMode(myRgb_LEDRGB_Green_PIN_D5, OUTPUT);
  69.     pinMode(myRgb_LEDRGB_Blue_PIN_D6, OUTPUT);
  70.  
  71. }
  72.  
  73. void loop(void)
  74. {
  75.     // put your main code here, to run repeatedly:
  76.  
  77.     updateOutputs(); // Refresh output data
  78.  
  79. }
  80.  
  81. void updateOutputs(void)
  82. {
  83.     digitalWrite(myRgb_LEDRGB_Red_PIN_D4, myRgb_LEDRGB_Red_PIN_D4_rawData);
  84.     digitalWrite(myRgb_LEDRGB_Green_PIN_D5, myRgb_LEDRGB_Green_PIN_D5_rawData);
  85.     digitalWrite(myRgb_LEDRGB_Blue_PIN_D6, myRgb_LEDRGB_Blue_PIN_D6_rawData);
  86. }
  87.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement