Advertisement
pleasedontcode

"Bluetooth Control" rev_01

Jun 2nd, 2024
694
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: "Bluetooth Control"
  13.     - Source Code NOT compiled for: Arduino Mega
  14.     - Source Code created on: 2024-06-03 01:07:15
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Create a retro console on Arduino using */
  21.     /* SoftwareSerial for dual Bluetooth HC-05 modules. */
  22.     /* The system initializes serial communication at */
  23.     /* 9600 baud for both modules, enabling wireless data */
  24.     /* transfer. */
  25. /****** END SYSTEM REQUIREMENTS *****/
  26.  
  27. /****** DEFINITION OF LIBRARIES *****/
  28. #include <SoftwareSerial.h>
  29.  
  30. /****** FUNCTION PROTOTYPES *****/
  31. void setup(void);
  32. void loop(void);
  33. void updateOutputs(void);
  34.  
  35. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  36. const uint8_t myLED_RGB_LEDRGB_Red_PIN_D2 = 2;
  37. const uint8_t myLED_RGB_LEDRGB_Green_PIN_D3 = 3;
  38. const uint8_t myLED_RGB_LEDRGB_Blue_PIN_D4 = 4;
  39.  
  40. /***** DEFINITION OF Software Serial *****/
  41. const uint8_t bluetooth_HC05_mySerial1_PIN_SERIAL_TX_A0 = A0;
  42. const uint8_t bluetooth_HC05_mySerial1_PIN_SERIAL_RX_A1 = A1;
  43. const uint8_t bluetooth_HC05_mySerial2_PIN_SERIAL_TX_A2 = A2;
  44. const uint8_t bluetooth_HC05_mySerial2_PIN_SERIAL_RX_A3 = A3;
  45.  
  46. // Instantiate SoftwareSerial objects for both Bluetooth modules
  47. SoftwareSerial bluetooth_HC05_mySerial1(bluetooth_HC05_mySerial1_PIN_SERIAL_RX_A1, bluetooth_HC05_mySerial1_PIN_SERIAL_TX_A0);
  48. SoftwareSerial bluetooth_HC05_mySerial2(bluetooth_HC05_mySerial2_PIN_SERIAL_RX_A3, bluetooth_HC05_mySerial2_PIN_SERIAL_TX_A2);
  49.  
  50. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  51. /***** used to store raw data *****/
  52. bool myLED_RGB_LEDRGB_Red_PIN_D2_rawData = 0;
  53. bool myLED_RGB_LEDRGB_Green_PIN_D3_rawData = 0;
  54. bool myLED_RGB_LEDRGB_Blue_PIN_D4_rawData = 0;
  55.  
  56. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  57. /***** used to store data after characteristic curve transformation *****/
  58. float myLED_RGB_LEDRGB_Red_PIN_D2_phyData = 0.0;
  59. float myLED_RGB_LEDRGB_Green_PIN_D3_phyData = 0.0;
  60. float myLED_RGB_LEDRGB_Blue_PIN_D4_phyData = 0.0;
  61.  
  62. void setup(void)
  63. {
  64.     // put your setup code here, to run once:
  65.  
  66.     pinMode(myLED_RGB_LEDRGB_Red_PIN_D2, OUTPUT);
  67.     pinMode(myLED_RGB_LEDRGB_Green_PIN_D3, OUTPUT);
  68.     pinMode(myLED_RGB_LEDRGB_Blue_PIN_D4, OUTPUT);
  69.  
  70.     // Initialize both Bluetooth modules at 9600 baud
  71.     bluetooth_HC05_mySerial1.begin(9600);
  72.     bluetooth_HC05_mySerial2.begin(9600);
  73. }
  74.  
  75. void loop(void)
  76. {
  77.     // put your main code here, to run repeatedly:
  78.  
  79.     updateOutputs(); // Refresh output data
  80.  
  81.     // Example of reading from one Bluetooth module and writing to another
  82.     if (bluetooth_HC05_mySerial1.available())
  83.     {
  84.         char data = bluetooth_HC05_mySerial1.read();
  85.         bluetooth_HC05_mySerial2.write(data);
  86.     }
  87.  
  88.     if (bluetooth_HC05_mySerial2.available())
  89.     {
  90.         char data = bluetooth_HC05_mySerial2.read();
  91.         bluetooth_HC05_mySerial1.write(data);
  92.     }
  93. }
  94.  
  95. void updateOutputs()
  96. {
  97.     digitalWrite(myLED_RGB_LEDRGB_Red_PIN_D2, myLED_RGB_LEDRGB_Red_PIN_D2_rawData);
  98.     digitalWrite(myLED_RGB_LEDRGB_Green_PIN_D3, myLED_RGB_LEDRGB_Green_PIN_D3_rawData);
  99.     digitalWrite(myLED_RGB_LEDRGB_Blue_PIN_D4, myLED_RGB_LEDRGB_Blue_PIN_D4_rawData);
  100. }
  101.  
  102. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement