Advertisement
pleasedontcode

**SMS Control** rev_03

Dec 5th, 2024
48
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:08:04
  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.  
  68. void setup(void)
  69. {
  70.     // put your setup code here, to run once:
  71.     pinMode(pot_X9C10X_CS_PIN_D2,    OUTPUT);
  72.     pinMode(pot_X9C10X_INC_PIN_D3,   OUTPUT);
  73.     pinMode(pot_X9C10X_UD_PIN_D4,    OUTPUT);
  74.  
  75.     gsm_SIM900A_Serial.begin(9600);
  76.    
  77.     // Initialize SIM900 module
  78.     if (gsm_SIM900A_Serial.available()) {
  79.         gsm_SIM900A_Serial.println("AT"); // Test AT command
  80.         delay(100);
  81.     }
  82. }
  83.  
  84. void loop(void)
  85. {
  86.     // put your main code here, to run repeatedly:
  87.     updateOutputs(); // Refresh output data
  88.     checkForSMS(); // Check for incoming SMS
  89. }
  90.  
  91. void updateOutputs()
  92. {
  93.     digitalWrite(pot_X9C10X_CS_PIN_D2, pot_X9C10X_CS_PIN_D2_rawData);
  94.     digitalWrite(pot_X9C10X_INC_PIN_D3, pot_X9C10X_INC_PIN_D3_rawData);
  95.     digitalWrite(pot_X9C10X_UD_PIN_D4, pot_X9C10X_UD_PIN_D4_rawData);
  96. }
  97.  
  98. void checkForSMS()
  99. {
  100.     if (gsm_SIM900A_Serial.available()) {
  101.         String sms = gsm_SIM900A_Serial.readString();
  102.         if (sms.indexOf("NEW_SMS") != -1) { // Assuming "NEW_SMS" is part of the SMS content
  103.             increasePotValue(5.0); // Increase pot value by 5%
  104.         }
  105.     }
  106. }
  107.  
  108. void increasePotValue(float percentage)
  109. {
  110.     // Assuming the potentiometer position is managed by a variable
  111.     static uint8_t currentPosition = 0; // Initialize current position
  112.     uint8_t increment = (uint8_t)(currentPosition * (percentage / 100.0));
  113.     currentPosition += increment; // Increase position
  114.     if (currentPosition > 255) currentPosition = 255; // Limit to max value
  115.     pot_X9C10X_INC_PIN_D3_rawData = currentPosition; // Update the raw data for the potentiometer
  116. }
  117.  
  118. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement