1
0
mirror of https://github.com/arduino/Arduino.git synced 2024-12-11 22:24:13 +01:00
Arduino/libraries/GSM/examples/MakeVoiceCall/MakeVoiceCall.ino

106 lines
2.7 KiB
Arduino
Raw Normal View History

2013-03-11 12:17:08 +01:00
/*
Make Voice Call
2013-03-11 12:17:08 +01:00
This sketch, for the Arduino GSM shield, puts a voice call to
a remote phone number that you enter through the serial monitor.
To make it work, open the serial monitor, and when you see the
READY message, type a phone number. Make sure the serial monitor
2013-03-11 12:17:08 +01:00
is set to send a just newline when you press return.
2013-03-11 12:17:08 +01:00
Circuit:
* GSM shield
* Voice circuit.
2013-03-11 12:17:08 +01:00
With no voice circuit the call will send nor receive any sound
2013-03-11 12:17:08 +01:00
created Mar 2012
by Javier Zorzano
2013-03-11 12:17:08 +01:00
This example is in the public domain.
*/
// libraries
#include <GSM.h>
// PIN Number
#define PINNUMBER ""
// initialize the library instance
GSM gsmAccess; // include a 'true' parameter for debug enabled
GSMVoiceCall vcs;
String remoteNumber = ""; // the number you will call
char charbuffer[20];
void setup() {
2013-03-11 12:17:08 +01: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 12:17:08 +01:00
}
Serial.println("Make Voice Call");
2013-03-11 12:17:08 +01:00
// connection state
boolean notConnected = true;
2013-03-11 12:17:08 +01: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 12:17:08 +01:00
notConnected = false;
} else {
2013-03-11 12:17:08 +01:00
Serial.println("Not connected");
delay(1000);
}
}
2013-03-11 12:17:08 +01:00
Serial.println("GSM initialized.");
Serial.println("Enter phone number to call.");
}
void loop() {
2013-03-11 12:17:08 +01:00
// add any incoming characters to the String:
while (Serial.available() > 0) {
2013-03-11 12:17:08 +01:00
char inChar = Serial.read();
// if it's a newline, that means you should make the call:
if (inChar == '\n') {
2013-03-11 12:17:08 +01:00
// make sure the phone number is not too long:
if (remoteNumber.length() < 20) {
2013-03-11 12:17:08 +01:00
// let the user know you're calling:
Serial.print("Calling to : ");
Serial.println(remoteNumber);
Serial.println();
// Call the remote number
remoteNumber.toCharArray(charbuffer, 20);
2013-03-11 12:17:08 +01:00
// Check if the receiving end has picked up the call
if (vcs.voiceCall(charbuffer)) {
2013-03-11 12:17:08 +01:00
Serial.println("Call Established. Enter line to end");
// Wait for some input from the line
while (Serial.read() != '\n' && (vcs.getvoiceCallStatus() == TALKING));
2013-03-11 12:17:08 +01:00
// And hang up
vcs.hangCall();
}
Serial.println("Call Finished");
remoteNumber = "";
2013-03-11 12:17:08 +01:00
Serial.println("Enter phone number to call.");
} else {
Serial.println("That's too long for a phone number. I'm forgetting it");
2013-03-11 12:17:08 +01:00
remoteNumber = "";
}
} else {
2013-03-11 12:17:08 +01:00
// add the latest character to the message to send:
if (inChar != '\r') {
2013-03-11 12:17:08 +01:00
remoteNumber += inChar;
}
2013-03-11 12:17:08 +01:00
}
}
2013-03-11 12:17:08 +01:00
}