pleasedontcode

Wireless Controller rev_03

Nov 4th, 2025
901
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: Wireless Controller
  13.     - Source Code NOT compiled for: Arduino Pro Mini 5V
  14.     - Source Code created on: 2025-11-05 01:35:46
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Check if digital data is received from bluetooth */
  21.     /* and and use this data into MCP4725. Read */
  22.     /* currentAcquisition and send it via bluetooth. The */
  23.     /* data to be send has to be integer. */
  24. /****** END SYSTEM REQUIREMENTS *****/
  25.  
  26.  
  27. /* START CODE */
  28.  
  29. /****** DEFINITION OF LIBRARIES *****/
  30. #include <SoftwareSerial.h>
  31. #include <Wire.h>
  32. #include <Adafruit_MCP4725.h>  //https://github.com/adafruit/Adafruit_MCP4725
  33.  
  34. /****** FUNCTION PROTOTYPES *****/
  35. void setup(void);
  36. void loop(void);
  37.  
  38. /***** DEFINITION OF ANALOG INPUT PINS *****/
  39. const uint8_t currentAcquisition_PIN_A0     = A0;
  40.  
  41. /***** DEFINITION OF Software Serial *****/
  42. const uint8_t DX_BT27_Slave_HC05_mySerial_PIN_SERIAL_TX_A1     = A1;
  43. const uint8_t DX_BT27_Slave_HC05_mySerial_PIN_SERIAL_RX_A2     = A2;
  44. SoftwareSerial DX_BT27_Slave_HC05_mySerial(DX_BT27_Slave_HC05_mySerial_PIN_SERIAL_RX_A2, DX_BT27_Slave_HC05_mySerial_PIN_SERIAL_TX_A1);
  45.  
  46. /***** DEFINITION OF I2C PINS *****/
  47. const uint8_t MCP4725_PIN_SDA_A4     = A4;
  48. const uint8_t MCP4725_PIN_SCL_A5     = A5;
  49.  
  50. /****** DEFINITION OF ANALOG INPUTS CHARACTERISTIC CURVES *****/
  51. const uint8_t SEGMENT_POINTS_voltage_Current_PIN_A0    = 2;
  52. const float voltage_Current_PIN_A0_lookup[2][SEGMENT_POINTS_voltage_Current_PIN_A0] =
  53. {
  54.     {0.0    ,   5.0},  //Voltage [V]
  55.     {0.0    ,   500.0}  //Current [A]
  56. };
  57.  
  58. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  59. Adafruit_MCP4725 dac;
  60.  
  61. // Add a variable to hold received Bluetooth data
  62. int receivedData = 0; // Assume integer data
  63.  
  64. void setup(void)
  65. {
  66.     // put your setup code here, to run once:
  67.  
  68.     dac.begin(0x62);
  69.  
  70.     xSerial.begin(9600);
  71.     Serial.begin(9600);
  72. }
  73.  
  74. void loop(void)
  75. {
  76.     // Read data from Bluetooth Serial if available
  77.     if (DX_BT27_Slave_HC05_mySerial.available()) {
  78.         // Read the incoming byte and convert to integer
  79.         receivedData = DX_BT27_Slave_HC05_mySerial.parseInt();
  80.         //Set the DAC voltage based on received data
  81.         dac.setVoltage(receivedData, false);
  82.         // Send back the currentAcquisition value
  83.         Serial.print("Current Acquisition: ");
  84.         Serial.println(receivedData);
  85.         // Send the currentAcquisition via Bluetooth
  86.         DX_BT27_Slave_HC05_mySerial.print("Current Acquisition: ");
  87.         DX_BT27_Slave_HC05_mySerial.println(receivedData);
  88.     }
  89.  
  90. // Read the sensor value and potentially process it if needed
  91. //uint16_t sensorValue = analogRead(currentAcquisition_PIN_A0); // Not used directly here
  92. }
  93.  
  94. /* END CODE */
  95.  
Advertisement
Add Comment
Please, Sign In to add comment