Using GSM Shield V3 with attachInterrupt
i need help, hastily. i'm trying trigger gsm send text message when 'interrupt' happens. except did not send text message. have got wrong somewhere? made out of combining button, interrupt , gsm basic codes.
#include <softwareserial.h>
#include <string.h>
softwareserial gprsserial(7, ;
const int buttonpin = 3; // number of pushbutton pin
const int ledpin = 13; // number of led pin
// variables change:
volatile int buttonstate = 0; // variable reading pushbutton status
void setup() {
gprsserial.begin(19200);
serial.begin(19200);
delay(500);
// initialize led pin output:
pinmode(ledpin, output);
// initialize pushbutton pin input:
pinmode(buttonpin, input);
// attach interrupt isr vector
attachinterrupt(0, pin_isr, change);
}
void loop() {
gprsserial.println();
if(buttonstate==1)
{
serial.println("supply on");
delay(100);
}
else
{
serial.println("supply off");
delay(100);
}
delay(5000);
}
void pin_isr() {
buttonstate = digitalread(buttonpin);
digitalwrite(ledpin, buttonstate);
sendtextmessage();
}
void sendtextmessage()
{
serial.println("sending text...");
gprsserial.println("at+cmgf=1\r");
delay(100);
gprsserial.println("at+cmgs = \"+??\"");
delay(100);
if(buttonstate==1)
{
gprsserial.println("supply on");
delay(100);
gprsserial.print((char)26);
delay(100);
}
else
{
gprsserial.println("supply off");
delay(100);
gprsserial.print((char)26);
delay(100);
}
gprsserial.println();
serial.println("text sent");
}
#include <softwareserial.h>
#include <string.h>
softwareserial gprsserial(7, ;
const int buttonpin = 3; // number of pushbutton pin
const int ledpin = 13; // number of led pin
// variables change:
volatile int buttonstate = 0; // variable reading pushbutton status
void setup() {
gprsserial.begin(19200);
serial.begin(19200);
delay(500);
// initialize led pin output:
pinmode(ledpin, output);
// initialize pushbutton pin input:
pinmode(buttonpin, input);
// attach interrupt isr vector
attachinterrupt(0, pin_isr, change);
}
void loop() {
gprsserial.println();
if(buttonstate==1)
{
serial.println("supply on");
delay(100);
}
else
{
serial.println("supply off");
delay(100);
}
delay(5000);
}
void pin_isr() {
buttonstate = digitalread(buttonpin);
digitalwrite(ledpin, buttonstate);
sendtextmessage();
}
void sendtextmessage()
{
serial.println("sending text...");
gprsserial.println("at+cmgf=1\r");
delay(100);
gprsserial.println("at+cmgs = \"+??\"");
delay(100);
if(buttonstate==1)
{
gprsserial.println("supply on");
delay(100);
gprsserial.print((char)26);
delay(100);
}
else
{
gprsserial.println("supply off");
delay(100);
gprsserial.print((char)26);
delay(100);
}
gprsserial.println();
serial.println("text sent");
}
sorry, somehow became smiley. @ softwareserialgprsserial(7,8)
Arduino Forum > Using Arduino > Programming Questions > Using GSM Shield V3 with attachInterrupt
arduino
Comments
Post a Comment