source: rtos_arduino/trunk/arduino_lib/libraries/GSM/examples/ReceiveVoiceCallGSM2/ReceiveVoiceCallGSM2.ino@ 136

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

ライブラリとOS及びベーシックなサンプルの追加.

File size: 3.0 KB
Line 
1/*
2 Receive Voice Call
3
4 This sketch, for the Arduino GSM shield, receives voice calls,
5 displays the calling number, waits a few seconds then hangs up.
6
7 Circuit:
8 * GSM shield
9 * Voice circuit. Refer to to the GSM shield getting started guide
10 at http://arduino.cc/en/Guide/ArduinoGSMShield#toc11
11 * SIM card that can accept voice calls
12
13 With no voice circuit the call will connect, but will not send or receive sound
14
15 created Mar 2012
16 by Javier Zorzano
17
18 This example is in the public domain.
19
20 http://arduino.cc/en/Tutorial/GSMExamplesReceiveVoiceCall
21
22
23 Added Arduino GSM Shield 2 features
24 modified Apr 2015
25 by Arduino.org team (http://arduino.org)
26 */
27
28// Include the GSM library
29#include <GSM.h>
30
31// PIN Number
32#define PINNUMBER ""
33
34// initialize the library instance
35GSM gsmAccess;
36GSM2 gsmAccessV2;
37GSMVoiceCall vcs;
38
39#define number_len 20 // define incoming call number lenght
40
41// Array to hold the number for the incoming call
42char number[number_len];
43
44void setup()
45{
46 // initialize serial communications and wait for port to open:
47 Serial.begin(9600);
48 while (!Serial) {
49 ; // wait for serial port to connect. Needed for Leonardo only
50 }
51
52 Serial.println("Receive Voice Call");
53
54 // connection state
55 boolean notConnected = true;
56
57 // Start GSM shield
58 // If your SIM has PIN, pass it as a parameter of begin() in quotes
59 while (notConnected)
60 {
61 if (gsmAccess.begin(PINNUMBER) == GSM_READY)
62 notConnected = false;
63 else
64 {
65 Serial.println("Not connected");
66 delay(1000);
67 }
68 }
69
70 // This makes sure the modem correctly reports incoming events
71 vcs.hangCall();
72 gsmAccessV2.muteControl(0); //not allowed by the module
73 gsmAccessV2.CommandEcho(1); // set echo
74 gsmAccessV2.speakerMode(1); //set speaker mode
75 gsmAccessV2.speakerLoudness(3); //set speaker loudness
76 gsmAccessV2.swapAudioChannel(1); //set audio channel
77 gsmAccessV2.microphoneGainLevel(1,13); //set microphone gain level
78 gsmAccessV2.ringerSoundLevel(20); //set ring sound level
79 gsmAccessV2.alertSoundMode(0); //set alert sound mode (sound)
80 gsmAccessV2.loudSpeakerVolumeLevel(20); //set loudspeaker volume level
81
82 Serial.println("Waiting for a call");
83}
84
85void loop()
86{
87 // Check the status of the voice call
88 switch (vcs.getvoiceCallStatus())
89 {
90 case IDLE_CALL: // Nothing is happening
91
92 break;
93
94 case RECEIVINGCALL: // Yes! Someone is calling us
95
96 Serial.println("RECEIVING CALL");
97
98
99 // Retrieve the calling number
100 vcs.retrieveCallingNumber(number, number_len);
101
102 // Print the calling number
103 Serial.print("Number:");
104 Serial.println(number);
105 Serial.println("Press a to answer");
106 while(Serial.read() !='a');
107 // Answer the call, establish the call
108 vcs.answerCall();
109 break;
110
111 case TALKING: // In this case the call would be established
112
113 Serial.println("TALKING. Press h to hang up.");
114 while (Serial.read() != 'h')
115 delay(100);
116 vcs.hangCall();
117 Serial.println("Hanging up and waiting for the next call.");
118 break;
119 }
120 delay(1000);
121}
122
123
Note: See TracBrowser for help on using the repository browser.