Arduino/libraries/GSM/examples/ReceiveVoiceCall/ReceiveVoiceCall.ino

102 lines
2.3 KiB
Arduino
Raw Normal View History

2013-03-11 04:17:08 -07:00
/*
Receive Voice Call
This sketch, for the Arduino GSM shield, receives voice calls,
2013-03-11 04:17:08 -07:00
displays the calling number, waits a few seconds then hangs up.
2013-03-11 04:17:08 -07:00
Circuit:
* GSM shield
2013-03-11 04:17:08 -07:00
* Voice circuit. Refer to to the GSM shield getting started guide
at http://www.arduino.cc/en/Guide/ArduinoGSMShield#toc11
2013-03-11 04:17:08 -07:00
* SIM card that can accept voice calls
2013-03-11 04:17:08 -07:00
With no voice circuit the call will connect, but will not send or receive sound
2013-03-11 04:17:08 -07:00
created Mar 2012
by Javier Zorzano
2013-03-11 04:17:08 -07:00
This example is in the public domain.
http://www.arduino.cc/en/Tutorial/GSMExamplesReceiveVoiceCall
2013-03-11 04:17:08 -07:00
*/
// Include the GSM library
#include <GSM.h>
// PIN Number
#define PINNUMBER ""
// initialize the library instance
GSM gsmAccess;
GSMVoiceCall vcs;
// Array to hold the number for the incoming call
char numtel[20];
2013-03-11 04:17:08 -07:00
void setup() {
2013-03-11 04:17:08 -07:00
// initialize serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
2013-03-11 04:17:08 -07:00
}
Serial.println("Receive Voice Call");
2013-03-11 04:17:08 -07:00
// connection state
boolean notConnected = true;
2013-03-11 04:17:08 -07:00
// 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) {
2013-03-11 04:17:08 -07:00
notConnected = false;
} else {
2013-03-11 04:17:08 -07:00
Serial.println("Not connected");
delay(1000);
}
}
2013-03-11 04:17:08 -07:00
// This makes sure the modem correctly reports incoming events
vcs.hangCall();
2013-03-11 04:17:08 -07:00
Serial.println("Waiting for a call");
}
void loop() {
2013-03-11 04:17:08 -07:00
// Check the status of the voice call
switch (vcs.getvoiceCallStatus()) {
2013-03-11 04:17:08 -07:00
case IDLE_CALL: // Nothing is happening
2013-03-11 04:17:08 -07:00
break;
2013-03-11 04:17:08 -07:00
case RECEIVINGCALL: // Yes! Someone is calling us
2013-03-11 04:17:08 -07:00
Serial.println("RECEIVING CALL");
2013-03-11 04:17:08 -07:00
// Retrieve the calling number
vcs.retrieveCallingNumber(numtel, 20);
2013-03-11 04:17:08 -07:00
// Print the calling number
Serial.print("Number:");
Serial.println(numtel);
2013-03-11 04:17:08 -07:00
// Answer the call, establish the call
vcs.answerCall();
2013-03-11 04:17:08 -07:00
break;
2013-03-11 04:17:08 -07:00
case TALKING: // In this case the call would be established
2013-03-11 04:17:08 -07:00
Serial.println("TALKING. Press enter to hang up.");
while (Serial.read() != '\n') {
2013-03-11 04:17:08 -07:00
delay(100);
}
2013-03-11 04:17:08 -07:00
vcs.hangCall();
Serial.println("Hanging up and waiting for the next call.");
2013-03-11 04:17:08 -07:00
break;
}
delay(1000);
}