Advertisement
pleasedontcode

"LED Control" rev_01

Jun 11th, 2024
283
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: "LED Control"
  13.     - Source Code NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2024-06-11 16:06:26
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* This code will 5 leds. The one entered in the app */
  21.     /* will light up when the time comes, until the */
  22.     /* person turns off the alarm */
  23. /****** END SYSTEM REQUIREMENTS *****/
  24.  
  25. /****** DEFINITION OF LIBRARIES *****/
  26. #include <SoftwareSerial.h>
  27. #include <EasyButton.h>  //https://github.com/evert-arias/EasyButton
  28.  
  29. /****** FUNCTION PROTOTYPES *****/
  30. void setup(void);
  31. void loop(void);
  32. void updateOutputs(void);
  33. void onAlarmButtonPressed(void);
  34.  
  35. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  36. const uint8_t alarmButton_PushButton_PIN_D5 = 5;
  37.  
  38. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  39. const uint8_t LEDRGB_Red_PIN_D2 = 2;
  40. const uint8_t LEDRGB_Green_PIN_D3 = 3;
  41. const uint8_t LEDRGB_Blue_PIN_D4 = 4;
  42. const uint8_t LED1_PIN_D6 = 6;
  43. const uint8_t LED2_PIN_D7 = 7;
  44. const uint8_t LED3_PIN_D8 = 8;
  45. const uint8_t LED4_PIN_D9 = 9;
  46. const uint8_t LED5_PIN_D10 = 10;
  47.  
  48. /***** DEFINITION OF Software Serial *****/
  49. const uint8_t HC05_mySerial_PIN_SERIAL_TX_A0 = A0;
  50. const uint8_t HC05_mySerial_PIN_SERIAL_RX_A1 = A1;
  51. SoftwareSerial HC05_mySerial(HC05_mySerial_PIN_SERIAL_RX_A1, HC05_mySerial_PIN_SERIAL_TX_A0);
  52.  
  53. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  54. /***** used to store raw data *****/
  55. bool LEDRGB_Red_PIN_D2_rawData = 0;
  56. bool LEDRGB_Green_PIN_D3_rawData = 0;
  57. bool LEDRGB_Blue_PIN_D4_rawData = 0;
  58. bool LED1_PIN_D6_rawData = 0;
  59. bool LED2_PIN_D7_rawData = 0;
  60. bool LED3_PIN_D8_rawData = 0;
  61. bool LED4_PIN_D9_rawData = 0;
  62. bool LED5_PIN_D10_rawData = 0;
  63.  
  64. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  65. /***** used to store data after characteristic curve transformation *****/
  66. float LEDRGB_Red_PIN_D2_phyData = 0.0;
  67. float LEDRGB_Green_PIN_D3_phyData = 0.0;
  68. float LEDRGB_Blue_PIN_D4_phyData = 0.0;
  69. float LED1_PIN_D6_phyData = 0.0;
  70. float LED2_PIN_D7_phyData = 0.0;
  71. float LED3_PIN_D8_phyData = 0.0;
  72. float LED4_PIN_D9_phyData = 0.0;
  73. float LED5_PIN_D10_phyData = 0.0;
  74.  
  75. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  76. EasyButton alarmButton(alarmButton_PushButton_PIN_D5);
  77.  
  78. void setup(void) {
  79.   // put your setup code here, to run once:
  80.   Serial.begin(115200);
  81.   Serial.println();
  82.   Serial.println(">>> EasyButton example with alarm button <<<");
  83.  
  84.   pinMode(LEDRGB_Red_PIN_D2, OUTPUT);
  85.   pinMode(LEDRGB_Green_PIN_D3, OUTPUT);
  86.   pinMode(LEDRGB_Blue_PIN_D4, OUTPUT);
  87.   pinMode(LED1_PIN_D6, OUTPUT);
  88.   pinMode(LED2_PIN_D7, OUTPUT);
  89.   pinMode(LED3_PIN_D8, OUTPUT);
  90.   pinMode(LED4_PIN_D9, OUTPUT);
  91.   pinMode(LED5_PIN_D10, OUTPUT);
  92.  
  93.   HC05_mySerial.begin(9600);
  94.  
  95.   // Initialize the button
  96.   alarmButton.begin();
  97.   alarmButton.onPressed(onAlarmButtonPressed);
  98. }
  99.  
  100. void loop(void) {
  101.   // put your main code here, to run repeatedly:
  102.   alarmButton.read();  // Read the button state
  103.   updateOutputs();     // Refresh output data
  104. }
  105.  
  106. void updateOutputs() {
  107.   digitalWrite(LEDRGB_Red_PIN_D2, LEDRGB_Red_PIN_D2_rawData);
  108.   digitalWrite(LEDRGB_Green_PIN_D3, LEDRGB_Green_PIN_D3_rawData);
  109.   digitalWrite(LEDRGB_Blue_PIN_D4, LEDRGB_Blue_PIN_D4_rawData);
  110.   digitalWrite(LED1_PIN_D6, LED1_PIN_D6_rawData);
  111.   digitalWrite(LED2_PIN_D7, LED2_PIN_D7_rawData);
  112.   digitalWrite(LED3_PIN_D8, LED3_PIN_D8_rawData);
  113.   digitalWrite(LED4_PIN_D9, LED4_PIN_D9_rawData);
  114.   digitalWrite(LED5_PIN_D10, LED5_PIN_D10_rawData);
  115. }
  116.  
  117. void onAlarmButtonPressed() {
  118.   Serial.println("Alarm button pressed");
  119.   // Add additional actions to be performed when the alarm button is pressed
  120.   // For example, turn off all LEDs
  121.   LEDRGB_Red_PIN_D2_rawData = 0;
  122.   LEDRGB_Green_PIN_D3_rawData = 0;
  123.   LEDRGB_Blue_PIN_D4_rawData = 0;
  124.   LED1_PIN_D6_rawData = 0;
  125.   LED2_PIN_D7_rawData = 0;
  126.   LED3_PIN_D8_rawData = 0;
  127.   LED4_PIN_D9_rawData = 0;
  128.   LED5_PIN_D10_rawData = 0;
  129.   updateOutputs();
  130. }
  131.  
  132. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement