Advertisement
pleasedontcode

**SMS Control** rev_04

Dec 5th, 2024
50
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:23:15
  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 increment);
  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. // Create an instance of the SIM900 class
  68. SIM900 gsmModule(&gsm_SIM900A_Serial);
  69.  
  70. void setup(void)
  71. {
  72.     // put your setup code here, to run once:
  73.  
  74.     pinMode(pot_X9C10X_CS_PIN_D2,    OUTPUT);
  75.     pinMode(pot_X9C10X_INC_PIN_D3,   OUTPUT);
  76.     pinMode(pot_X9C10X_UD_PIN_D4,    OUTPUT);
  77.  
  78.     gsm_SIM900A_Serial.begin(9600);
  79.     gsmModule.handshake(); // Initialize GSM module
  80. }
  81.  
  82. void loop(void)
  83. {
  84.     // put your main code here, to run repeatedly:
  85.     checkForSMS(); // Check for incoming SMS
  86.     updateOutputs(); // Refresh output data
  87. }
  88.  
  89. void updateOutputs()
  90. {
  91.     digitalWrite(pot_X9C10X_CS_PIN_D2, pot_X9C10X_CS_PIN_D2_rawData);
  92.     digitalWrite(pot_X9C10X_INC_PIN_D3, pot_X9C10X_INC_PIN_D3_rawData);
  93.     digitalWrite(pot_X9C10X_UD_PIN_D4, pot_X9C10X_UD_PIN_D4_rawData);
  94. }
  95.  
  96. void checkForSMS()
  97. {
  98.     if (gsmModule.isCardReady())
  99.     {
  100.         String message = gsmModule.getResponse(); // Get the SMS message
  101.         if (message.length() > 0) // If a new SMS is received
  102.         {
  103.             increasePotValue(5.0); // Increase potentiometer value by 5%
  104.         }
  105.     }
  106. }
  107.  
  108. void increasePotValue(float increment)
  109. {
  110.     // Assuming the potentiometer value is represented in percentage
  111.     pot_X9C10X_INC_PIN_D3_phyData += increment; // Increase pot value
  112.     if (pot_X9C10X_INC_PIN_D3_phyData > 100.0) // Limit to 100%
  113.     {
  114.         pot_X9C10X_INC_PIN_D3_phyData = 100.0;
  115.     }
  116.     pot_X9C10X_INC_PIN_D3_rawData = (int)(pot_X9C10X_INC_PIN_D3_phyData / 100.0 * 255); // Convert to raw data
  117. }
  118.  
  119. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement