Advertisement
RuiViana

GSM

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