Advertisement
pleasedontcode

**GSM Control** rev_05

Dec 5th, 2024
53
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: **GSM Control**
  13.     - Source Code NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2024-12-05 23:28:20
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Develop a project utilizing the SIM900 GSM module */
  21.     /* for sending and receiving SMS messages. Ensure the */
  22.     /* SoftwareSerial interface on A0 and A1 is */
  23.     /* configured for seamless communication and */
  24.     /* implement basic command responses. */
  25. /****** SYSTEM REQUIREMENT 2 *****/
  26.     /* each time receive a new sms so increase pot value */
  27.     /* of 5% */
  28. /****** END SYSTEM REQUIREMENTS *****/
  29.  
  30.  
  31. /********* User code review feedback **********
  32. #### Feedback 1 ####
  33. - initialize X9C10X library
  34. ********* User code review feedback **********/
  35.  
  36. /* START CODE */
  37.  
  38. /****** DEFINITION OF LIBRARIES *****/
  39. #include <SoftwareSerial.h>
  40. #include <sim900.h> //https://github.com/nthnn
  41. #include <X9C10X.h> //https://github.com/RobTillaart/X9C10X
  42.  
  43. /****** FUNCTION PROTOTYPES *****/
  44. void setup(void);
  45. void loop(void);
  46. void updateOutputs();
  47. void checkForSMS();
  48. void increasePotValue(float increment);
  49.  
  50. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  51. const uint8_t pot_X9C10X_CS_PIN_D2      = 2;
  52. const uint8_t pot_X9C10X_INC_PIN_D3     = 3;
  53. const uint8_t pot_X9C10X_UD_PIN_D4      = 4;
  54.  
  55. /***** DEFINITION OF Software Serial *****/
  56. const uint8_t gsm_SIM900A_Serial_PIN_SERIAL_TX_A0       = A0;
  57. const uint8_t gsm_SIM900A_Serial_PIN_SERIAL_RX_A1       = A1;
  58. SoftwareSerial gsm_SIM900A_Serial(gsm_SIM900A_Serial_PIN_SERIAL_RX_A1, gsm_SIM900A_Serial_PIN_SERIAL_TX_A0);
  59.  
  60. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  61. /***** used to store raw data *****/
  62. bool    pot_X9C10X_CS_PIN_D2_rawData        = 0;
  63. bool    pot_X9C10X_INC_PIN_D3_rawData       = 0;
  64. bool    pot_X9C10X_UD_PIN_D4_rawData        = 0;
  65.  
  66. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  67. /***** used to store data after characteristic curve transformation *****/
  68. float   pot_X9C10X_CS_PIN_D2_phyData        = 0.0;
  69. float   pot_X9C10X_INC_PIN_D3_phyData       = 0.0;
  70. float   pot_X9C10X_UD_PIN_D4_phyData        = 0.0;
  71.  
  72. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  73. // Create an instance of the SIM900 class
  74. SIM900 gsmModule(&gsm_SIM900A_Serial);
  75. // Create an instance of the X9C10X class
  76. X9C10X potentiometer;
  77.  
  78. void setup(void)
  79. {
  80.     // put your setup code here, to run once:
  81.  
  82.     pinMode(pot_X9C10X_CS_PIN_D2,    OUTPUT);
  83.     pinMode(pot_X9C10X_INC_PIN_D3,   OUTPUT);
  84.     pinMode(pot_X9C10X_UD_PIN_D4,    OUTPUT);
  85.  
  86.     gsm_SIM900A_Serial.begin(9600);
  87.     gsmModule.handshake(); // Initialize GSM module
  88.  
  89.     // Initialize the potentiometer
  90.     potentiometer.begin(pot_X9C10X_INC_PIN_D3, pot_X9C10X_UD_PIN_D4, pot_X9C10X_CS_PIN_D2);
  91. }
  92.  
  93. void loop(void)
  94. {
  95.     // put your main code here, to run repeatedly:
  96.     checkForSMS(); // Check for incoming SMS
  97.     updateOutputs(); // Refresh output data
  98. }
  99.  
  100. void updateOutputs()
  101. {
  102.     digitalWrite(pot_X9C10X_CS_PIN_D2, pot_X9C10X_CS_PIN_D2_rawData);
  103.     digitalWrite(pot_X9C10X_INC_PIN_D3, pot_X9C10X_INC_PIN_D3_rawData);
  104.     digitalWrite(pot_X9C10X_UD_PIN_D4, pot_X9C10X_UD_PIN_D4_rawData);
  105. }
  106.  
  107. void checkForSMS()
  108. {
  109.     if (gsmModule.isCardReady())
  110.     {
  111.         String message = gsmModule.getResponse(); // Get the SMS message
  112.         if (message.length() > 0) // If a new SMS is received
  113.         {
  114.             increasePotValue(5.0); // Increase potentiometer value by 5%
  115.         }
  116.     }
  117. }
  118.  
  119. void increasePotValue(float increment)
  120. {
  121.     // Assuming the potentiometer value is represented in percentage
  122.     pot_X9C10X_INC_PIN_D3_phyData += increment; // Increase pot value
  123.     if (pot_X9C10X_INC_PIN_D3_phyData > 100.0) // Limit to 100%
  124.     {
  125.         pot_X9C10X_INC_PIN_D3_phyData = 100.0;
  126.     }
  127.     pot_X9C10X_INC_PIN_D3_rawData = (int)(pot_X9C10X_INC_PIN_D3_phyData / 100.0 * 255); // Convert to raw data
  128. }
  129.  
  130. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement