source: rtos_arduino/trunk/arduino_lib/hardware/arduino/samd/libraries/GSM/examples/MakeVoiceCall/MakeVoiceCall.ino@ 175

Last change on this file since 175 was 175, checked in by ertl-honda, 8 years ago

ライブラリを Arduino IDE 1.7.9 にupdate

File size: 2.9 KB
Line 
1/*
2 Make Voice Call
3
4 This sketch, for the Arduino GSM shield, puts a voice call to
5 a remote phone number that you enter through the serial monitor.
6 To make it work, open the serial monitor, and when you see the
7 READY message, type a phone number. Make sure the serial monitor
8 is set to send a just newline when you press return.
9
10 Circuit:
11 * GSM shield
12 * Voice circuit.
13 With no voice circuit the call will send nor receive any sound
14
15 ATTENTION: to work correctly with M0/M0 pro you have to connect pin 2 to pin 4 of the shield
16
17
18 created Mar 2012
19 by Javier Zorzano
20
21 This example is in the public domain.
22 */
23
24// libraries
25#include <GSM.h>
26
27// PIN Number
28#define PINNUMBER ""
29
30// initialize the library instance
31GSM gsmAccess; // include a 'true' parameter for debug enabled
32GSMVoiceCall vcs;
33
34String remoteNumber = ""; // the number you will call
35char charbuffer[20];
36
37void setup()
38{
39
40 // initialize serial communications and wait for port to open:
41 SerialUSB.begin(9600);
42 while (!SerialUSB) {
43 ; // wait for serial port to connect. Needed for Leonardo only
44 }
45
46 SerialUSB.println("Make Voice Call");
47
48 // connection state
49 boolean notConnected = true;
50
51 // Start GSM shield
52 // If your SIM has PIN, pass it as a parameter of begin() in quotes
53 while (notConnected)
54 {
55 if (gsmAccess.begin(PINNUMBER) == GSM_READY)
56 notConnected = false;
57 else
58 {
59 SerialUSB.println("Not connected");
60 delay(1000);
61 }
62 }
63
64 SerialUSB.println("GSM initialized.");
65 SerialUSB.println("Enter phone number to call.");
66
67}
68
69void loop()
70{
71
72 // add any incoming characters to the String:
73 while (SerialUSB.available() > 0)
74 {
75 char inChar = SerialUSB.read();
76 // if it's a newline, that means you should make the call:
77 if (inChar == '\n')
78 {
79 // make sure the phone number is not too long:
80 if (remoteNumber.length() < 20)
81 {
82 // let the user know you're calling:
83 SerialUSB.print("Calling to : ");
84 SerialUSB.println(remoteNumber);
85 SerialUSB.println();
86
87 // Call the remote number
88 remoteNumber.toCharArray(charbuffer, 20);
89
90
91 // Check if the receiving end has picked up the call
92 if (vcs.voiceCall(charbuffer))
93 {
94 SerialUSB.println("Call Established. Enter line to end");
95 // Wait for some input from the line
96 while (SerialUSB.read() != '\n' && (vcs.getvoiceCallStatus() == TALKING));
97 // And hang up
98 vcs.hangCall();
99 }
100 SerialUSB.println("Call Finished");
101 remoteNumber = "";
102 SerialUSB.println("Enter phone number to call.");
103 }
104 else
105 {
106 SerialUSB.println("That's too long for a phone number. I'm forgetting it");
107 remoteNumber = "";
108 }
109 }
110 else
111 {
112 // add the latest character to the message to send:
113 if (inChar != '\r')
114 remoteNumber += inChar;
115 }
116 }
117}
118
Note: See TracBrowser for help on using the repository browser.