Advertisement
pleasedontcode

**SMS Control** rev_06

Dec 5th, 2024
45
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: **SMS Control**
  13.     - Source Code NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2024-12-05 23:31:01
  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. #### Feedback 2 ####
  35. - increasepotvalue using library.
  36. ********* User code review feedback **********/
  37.  
  38. /* START CODE */
  39.  
  40. /****** DEFINITION OF LIBRARIES *****/
  41. #include <SoftwareSerial.h>
  42. #include <sim900.h> //https://github.com/nthnn
  43. #include <X9C10X.h> //https://github.com/RobTillaart/X9C10X
  44.  
  45. /****** FUNCTION PROTOTYPES *****/
  46. void setup(void);
  47. void loop(void);
  48. void updateOutputs();
  49. void checkForSMS();
  50. void increasePotValue(float increment);
  51.  
  52. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  53. const uint8_t pot_X9C10X_CS_PIN_D2      = 2;
  54. const uint8_t pot_X9C10X_INC_PIN_D3     = 3;
  55. const uint8_t pot_X9C10X_UD_PIN_D4      = 4;
  56.  
  57. /***** DEFINITION OF Software Serial *****/
  58. const uint8_t gsm_SIM900A_Serial_PIN_SERIAL_TX_A0       = A0;
  59. const uint8_t gsm_SIM900A_Serial_PIN_SERIAL_RX_A1       = A1;
  60. SoftwareSerial gsm_SIM900A_Serial(gsm_SIM900A_Serial_PIN_SERIAL_RX_A1, gsm_SIM900A_Serial_PIN_SERIAL_TX_A0);
  61.  
  62. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  63. /***** used to store raw data *****/
  64. bool    pot_X9C10X_CS_PIN_D2_rawData        = 0;
  65. bool    pot_X9C10X_INC_PIN_D3_rawData       = 0;
  66. bool    pot_X9C10X_UD_PIN_D4_rawData        = 0;
  67.  
  68. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  69. /***** used to store data after characteristic curve transformation *****/
  70. float   pot_X9C10X_CS_PIN_D2_phyData        = 0.0;
  71. float   pot_X9C10X_INC_PIN_D3_phyData       = 0.0;
  72. float   pot_X9C10X_UD_PIN_D4_phyData        = 0.0;
  73.  
  74. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  75. // Create an instance of the SIM900 class
  76. SIM900 gsmModule(&gsm_SIM900A_Serial);
  77. // Create an instance of the X9C10X class
  78. X9C10X potentiometer;
  79.  
  80. void setup(void)
  81. {
  82.     // put your setup code here, to run once:
  83.  
  84.     pinMode(pot_X9C10X_CS_PIN_D2,    OUTPUT);
  85.     pinMode(pot_X9C10X_INC_PIN_D3,   OUTPUT);
  86.     pinMode(pot_X9C10X_UD_PIN_D4,    OUTPUT);
  87.  
  88.     gsm_SIM900A_Serial.begin(9600);
  89.     gsmModule.handshake(); // Initialize GSM module
  90.  
  91.     // Initialize the potentiometer
  92.     potentiometer.begin(pot_X9C10X_INC_PIN_D3, pot_X9C10X_UD_PIN_D4, pot_X9C10X_CS_PIN_D2);
  93. }
  94.  
  95. void loop(void)
  96. {
  97.     // put your main code here, to run repeatedly:
  98.     checkForSMS(); // Check for incoming SMS
  99.     updateOutputs(); // Refresh output data
  100. }
  101.  
  102. void updateOutputs()
  103. {
  104.     digitalWrite(pot_X9C10X_CS_PIN_D2, pot_X9C10X_CS_PIN_D2_rawData);
  105.     digitalWrite(pot_X9C10X_INC_PIN_D3, pot_X9C10X_INC_PIN_D3_rawData);
  106.     digitalWrite(pot_X9C10X_UD_PIN_D4, pot_X9C10X_UD_PIN_D4_rawData);
  107. }
  108.  
  109. void checkForSMS()
  110. {
  111.     if (gsmModule.isCardReady())
  112.     {
  113.         String message = gsmModule.getResponse(); // Get the SMS message
  114.         if (message.length() > 0) // If a new SMS is received
  115.         {
  116.             increasePotValue(5.0); // Increase potentiometer value by 5%
  117.         }
  118.     }
  119. }
  120.  
  121. void increasePotValue(float increment)
  122. {
  123.     // Increase the potentiometer value by the specified increment
  124.     potentiometer.incr(); // Use the library function to increase the potentiometer value
  125. }
  126.  
  127. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement