Hi
I'm new in Arduino, but familiard with PLCs code.
However, I'd like to choose message before send it.
I'm able to send using example from library. But after code upgrading, (even compile successful ) not.
Goal is to send SMS. But before sending, with variable t I'd like to choose a message. That works, but SMS is not sended.
(SMS is send after button is pressed -> a subrutine for sending SMS is called.)
Can you please help me?
Thank you in advance.
Til
Here is my code:
This example is in the public domain.
http://arduino.cc/en/Tutorial/GSMExamplesSendSMS
*/
const int DIn8 = 8; //Button
const int LedGN = 10; //LED Green
boolean SendSMS = false;
int Din8Stat = 0; //Input8 status
int t=1;
char Alarm = 'Sprozen je alarm';
#include <GSM.h> // Include the GSM library
#define PINNUMBER ""
// initialize the library instance
GSM gsmAccess;
GSM_SMS sms;
void setup()
{
pinMode(DIn8, INPUT); //Mode define
pinMode(LedGN, OUTPUT); //Mode define
// initialize serial communications and wait for port to open:
Serial.begin(9600);
// while (!Serial) {
Serial.println("SMS Messages Sender");
// connection state
boolean notConnected = true;
// Start GSM shield
// If your SIM has PIN, pass it as a parameter of begin() in quotes
while (notConnected)
{
if (gsmAccess.begin(PINNUMBER) == GSM_READY)
notConnected = false;
else
{
Serial.println("Not connected");
delay(1000);
}
}
digitalWrite(LedGN,HIGH);
Serial.println("GSM initialized");
}
//PROGRAM START ***************************************************************************
void loop(){
int Din8Stat = digitalRead(DIn8); //Read input 8 -Button
int t = 2; //Choose text to send
if(Din8Stat == HIGH) //Enable: If In8=1 send SMS
SendTextMessage(); //call conditionalsubrutine: SendTextMessage
delay(500); //Pause
Serial.println("Press button to send SMS");
}
//PROGRAM END ****************************************************************************
//********************************************************************************************
void SendTextMessage(){ //Send SMS
char* txtMsg[] ={"This is string 1", "This is string 2", "This is string 3", //Messages
"This is string 4", "This is string 5","This is string 6"};
char remoteNum [20] = "123456789"; // define phone number to send sms
Serial.print("To GSM number: "); //Chck phone no.
Serial.println(remoteNum);
// Serial.println(t);
Serial.print("Message:"); //show msg to be send
Serial.println(txtMsg[t]);
//send the message:
sms.beginSMS(remoteNum);
sms.print(txtMsg[t]); //???Is this OK?
sms.endSMS();
Serial.println("\nCOMPLETE!\n");
Prek:
delay(100);
}
//}
// Read input serial
int readSerial(char result[])
{
int i = 0;
while (1)
{
while (Serial.available() > 0)
{
char inChar = Serial.read();
if (inChar == '\n')
{
result[i] = '\0';
Serial.flush();
return 0;
}
if (inChar != '\r')
{
result[i] = inChar;
i++;
}
}
}
}