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

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

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

File size: 2.2 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
24// Include the GSM library
25#include <GSM.h>
26
27// PIN Number
28#define PINNUMBER ""
29
30// initialize the library instance
31GSM gsmAccess;
32GSMVoiceCall vcs;
33
34// Array to hold the number for the incoming call
35char numtel[20];
36
37void setup()
38{
39 // initialize serial communications and wait for port to open:
40 Serial.begin(9600);
41 while (!Serial) {
42 ; // wait for serial port to connect. Needed for Leonardo only
43 }
44
45 Serial.println("Receive Voice Call");
46
47 // connection state
48 boolean notConnected = true;
49
50 // Start GSM shield
51 // If your SIM has PIN, pass it as a parameter of begin() in quotes
52 while (notConnected)
53 {
54 if (gsmAccess.begin(PINNUMBER) == GSM_READY)
55 notConnected = false;
56 else
57 {
58 Serial.println("Not connected");
59 delay(1000);
60 }
61 }
62
63 // This makes sure the modem correctly reports incoming events
64 vcs.hangCall();
65
66 Serial.println("Waiting for a call");
67}
68
69void loop()
70{
71 // Check the status of the voice call
72 switch (vcs.getvoiceCallStatus())
73 {
74 case IDLE_CALL: // Nothing is happening
75
76 break;
77
78 case RECEIVINGCALL: // Yes! Someone is calling us
79
80 Serial.println("RECEIVING CALL");
81
82 // Retrieve the calling number
83 vcs.retrieveCallingNumber(numtel, 20);
84
85 // Print the calling number
86 Serial.print("Number:");
87 Serial.println(numtel);
88
89 // Answer the call, establish the call
90 vcs.answerCall();
91 break;
92
93 case TALKING: // In this case the call would be established
94
95 Serial.println("TALKING. Press enter to hang up.");
96 while (Serial.read() != '\n')
97 delay(100);
98 vcs.hangCall();
99 Serial.println("Hanging up and waiting for the next call.");
100 break;
101 }
102 delay(1000);
103}
104
105
Note: See TracBrowser for help on using the repository browser.