Advertisement
RuiViana

GSM2

Jul 14th, 2015
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1.  
  2. //SMS receiver
  3.  
  4. // libraries
  5. #include <GSM.h>
  6.  
  7.  
  8. float desconto;
  9. float resul_desconto;
  10.  
  11. // PIN Number
  12. #define PINNUMBER ""
  13.  
  14. // initialize the library instance
  15. GSM gsmAccess; // include a 'true' parameter for debug enabled
  16. GSM_SMS sms;
  17.  
  18. char remoteNumber[20]; // Holds the emitting number
  19.  
  20. void setup()
  21. {
  22. // initialize serial communications
  23. Serial.begin(9600);
  24.  
  25. Serial.println("SMS Concessiornaria");
  26.  
  27. // connection state
  28. boolean notConnected = true;
  29.  
  30. // Start GSM shield
  31. // If your SIM has PIN, pass it as a parameter of begin() in quotes
  32. while(notConnected)
  33. {
  34. if(gsmAccess.begin(PINNUMBER)==GSM_READY)
  35. notConnected = false;
  36. else
  37. {
  38. Serial.println("Não Conectado");
  39. delay(1000);
  40. }
  41. }
  42.  
  43. Serial.println("GSM Inicializado");
  44. //Serial.println("Waiting for messages");
  45. }
  46.  
  47. void loop()
  48. {
  49. char c;
  50.  
  51. // If there are any SMSs available()
  52. if (sms.available())
  53. {
  54. Serial.println("Mensagem Recebida");
  55.  
  56. // Get remote number
  57. sms.remoteNumber(remoteNumber, 20);
  58. Serial.println(remoteNumber);
  59.  
  60. // This is just an example of message disposal
  61. // Messages starting with # should be discarded
  62. if(sms.peek()=='#')
  63. {
  64. //Serial.println("Discarded SMS");
  65. sms.flush();
  66. }
  67.  
  68. // Read message bytes and print them
  69. Serial.println("Voce Recarregou (R$):");
  70. while(c=sms.parseInt())
  71. Serial.print(c);
  72.  
  73. //Serial.println("\nEND OF MESSAGE");
  74.  
  75. // delete message from modem memory
  76. sms.flush();
  77. //Serial.println("MESSAGE DELETED");
  78.  
  79.  
  80. // Desconto do valor da msg
  81.  
  82. int resul = int (c);
  83.  
  84. desconto = (resul-5);
  85. resul_desconto = resul_desconto + desconto;
  86.  
  87. Serial.print("Valor recebido com 5 reais descontado: ");
  88. Serial.println(desconto,10);
  89. Serial.print("Valor acumulado: ");
  90. Serial.println(resul_desconto,10);
  91.  
  92. }
  93.  
  94. delay(1000);
  95.  
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement