Advertisement
pleasedontcode

**SMS Control** rev_07

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: **SMS Control**
  13.     - Source Code NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2024-12-05 23:32:41
  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. /* START CODE */
  31.  
  32. /****** DEFINITION OF LIBRARIES *****/
  33. #include <SoftwareSerial.h>
  34. #include <sim900.h> //https://github.com/nthnn
  35. #include <X9C10X.h> //https://github.com/RobTillaart/X9C10X
  36.  
  37. /****** FUNCTION PROTOTYPES *****/
  38. void setup(void);
  39. void loop(void);
  40. void updateOutputs();
  41. void checkForSMS();
  42. void increasePotValue(float percentage);
  43.  
  44. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  45. const uint8_t pot_X9C10X_CS_PIN_D2      = 2;
  46. const uint8_t pot_X9C10X_INC_PIN_D3     = 3;
  47. const uint8_t pot_X9C10X_UD_PIN_D4      = 4;
  48.  
  49. /***** DEFINITION OF Software Serial *****/
  50. const uint8_t gsm_SIM900A_Serial_PIN_SERIAL_TX_A0       = A0;
  51. const uint8_t gsm_SIM900A_Serial_PIN_SERIAL_RX_A1       = A1;
  52. SoftwareSerial gsm_SIM900A_Serial(gsm_SIM900A_Serial_PIN_SERIAL_RX_A1, gsm_SIM900A_Serial_PIN_SERIAL_TX_A0);
  53.  
  54. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  55. /***** used to store raw data *****/
  56. bool    pot_X9C10X_CS_PIN_D2_rawData        = 0;
  57. bool    pot_X9C10X_INC_PIN_D3_rawData       = 0;
  58. bool    pot_X9C10X_UD_PIN_D4_rawData        = 0;
  59.  
  60. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  61. /***** used to store data after characteristic curve transformation *****/
  62. float   pot_X9C10X_CS_PIN_D2_phyData        = 0.0;
  63. float   pot_X9C10X_INC_PIN_D3_phyData       = 0.0;
  64. float   pot_X9C10X_UD_PIN_D4_phyData        = 0.0;
  65.  
  66. /****** DEFINITION OF LIBRARIES CLASS INSTANCES *****/
  67. SIM900 gsmModule(&gsm_SIM900A_Serial); // Instantiate SIM900 object
  68.  
  69. void setup(void)
  70. {
  71.     // put your setup code here, to run once:
  72.     pinMode(pot_X9C10X_CS_PIN_D2,    OUTPUT);
  73.     pinMode(pot_X9C10X_INC_PIN_D3,   OUTPUT);
  74.     pinMode(pot_X9C10X_UD_PIN_D4,    OUTPUT);
  75.  
  76.     gsm_SIM900A_Serial.begin(9600);
  77.     gsmModule.handshake(); // Initialize GSM module
  78. }
  79.  
  80. void loop(void)
  81. {
  82.     // put your main code here, to run repeatedly:
  83.     updateOutputs(); // Refresh output data
  84.     checkForSMS(); // Check for incoming SMS
  85. }
  86.  
  87. void updateOutputs()
  88. {
  89.     digitalWrite(pot_X9C10X_CS_PIN_D2, pot_X9C10X_CS_PIN_D2_rawData);
  90.     digitalWrite(pot_X9C10X_INC_PIN_D3, pot_X9C10X_INC_PIN_D3_rawData);
  91.     digitalWrite(pot_X9C10X_UD_PIN_D4, pot_X9C10X_UD_PIN_D4_rawData);
  92. }
  93.  
  94. void checkForSMS()
  95. {
  96.     if (gsmModule.isCardReady()) {
  97.         String sms = gsmModule.getResponse(); // Get the SMS content
  98.         if (sms.length() > 0) {
  99.             increasePotValue(5.0); // Increase pot value by 5%
  100.         }
  101.     }
  102. }
  103.  
  104. void increasePotValue(float percentage)
  105. {
  106.     // Assuming the potentiometer value is represented in a range of 0-100
  107.     float currentValue = pot_X9C10X_INC_PIN_D3_phyData; // Get current potentiometer value
  108.     float increment = currentValue * (percentage / 100.0); // Calculate increment
  109.     currentValue += increment; // Increase the value
  110.     pot_X9C10X_INC_PIN_D3_phyData = constrain(currentValue, 0.0, 100.0); // Ensure it's within bounds
  111.     pot_X9C10X_INC_PIN_D3_rawData = (bool)(pot_X9C10X_INC_PIN_D3_phyData > 0); // Update raw data
  112. }
  113.  
  114. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement