Advertisement
pleasedontcode

"LED Control" rev_02

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