@@ -13,117 +13,133 @@ UBX_CELL_VOICE_BASE myModule; // This example works with all voice-enabled modul
13
13
14
14
void setup ()
15
15
{
16
- Serial.begin (115200 ); // Start the serial console
17
-
18
- // Wait for user to press key to begin
19
- Serial.println (F (" u-blox Cellular Audio Example 1 - Play Tone" ));
20
-
21
- Serial.println ();
22
- Serial.println (F (" ! ! ! ! ! ATTENTION ! ! ! ! ! ATTENTION ! ! ! ! ! ATTENTION ! ! ! ! !" ));
23
- Serial.println (F (" This example requires an audio codec attached to the I2S interface" ));
24
- Serial.println (F (" of the cellular modem. Please add one and update this example as" ));
25
- Serial.println (F (" needed to configure your audio codec!" ));
26
- Serial.println (F (" ! ! ! ! ! ATTENTION ! ! ! ! ! ATTENTION ! ! ! ! ! ATTENTION ! ! ! ! !" ));
27
- Serial.println ();
28
-
29
- Serial.println (F (" Press any key to begin" ));
30
-
31
- while (!Serial.available ()) // Wait for the user to press a key (send any serial character)
32
- ;
33
- while (Serial.available ()) // Empty the serial RX buffer
34
- Serial.read ();
35
-
36
- Serial.println (F (" Beginning..." ));
37
-
38
- // myModule.enableDebugging(); // Uncomment this line to enable helpful debug messages on Serial
39
-
40
- // For the MicroMod Asset Tracker, we need to invert the power pin so it pulls high instead of low
41
- // Uncomment the next line if required
42
- // myModule.invertPowerPin(true);
43
-
44
- // Initialize the module
45
- if (myModule.begin (mySerial, UBX_CELL_DEFAULT_BAUD_RATE) )
46
- {
47
- Serial.println (F (" Module connected!" ));
48
- }
49
- else
50
- {
51
- Serial.println (F (" Unable to communicate with the module." ));
52
- Serial.println (F (" Manually power-on (hold the module's On button for 3 seconds) and try again." ));
53
- while (1 ) ; // Loop forever on fail
54
- }
55
- Serial.println ();
16
+ Serial.begin (115200 ); // Start the serial console
17
+
18
+ // Wait for user to press key to begin
19
+ Serial.println (F (" u-blox Cellular Audio Example 1 - Play Tone" ));
20
+
21
+ Serial.println ();
22
+ Serial.println (F (" ! ! ! ! ! ATTENTION ! ! ! ! ! ATTENTION ! ! ! ! ! ATTENTION ! ! ! ! !" ));
23
+ Serial.println (F (" This example requires an audio codec attached to the I2S interface" ));
24
+ Serial.println (F (" of the cellular modem. Please add one and update this example as" ));
25
+ Serial.println (F (" needed to configure your audio codec!" ));
26
+ Serial.println (F (" ! ! ! ! ! ATTENTION ! ! ! ! ! ATTENTION ! ! ! ! ! ATTENTION ! ! ! ! !" ));
27
+ Serial.println ();
28
+
29
+ Serial.println (F (" Press any key to begin" ));
30
+
31
+ while (!Serial.available ()) // Wait for the user to press a key (send any serial character)
32
+ ;
33
+ while (Serial.available ()) // Empty the serial RX buffer
34
+ Serial.read ();
35
+
36
+ Serial.println (F (" Beginning..." ));
37
+
38
+ // myModule.enableDebugging(); // Uncomment this line to enable helpful debug messages on Serial
39
+
40
+ // For the MicroMod Asset Tracker, we need to invert the power pin so it pulls high instead of low
41
+ // Uncomment the next line if required
42
+ // myModule.invertPowerPin(true);
43
+
44
+ // Initialize the module
45
+ if (myModule.begin (mySerial, UBX_CELL_DEFAULT_BAUD_RATE))
46
+ {
47
+ Serial.println (F (" Module connected!" ));
48
+ }
49
+ else
50
+ {
51
+ Serial.println (F (" Unable to communicate with the module." ));
52
+ Serial.println (F (" Manually power-on (hold the module's On button for 3 seconds) and try again." ));
53
+ while (1 )
54
+ ; // Loop forever on fail
55
+ }
56
+ Serial.println ();
56
57
}
57
58
58
59
void loop ()
59
60
{
60
- String inputString;
61
- char dtmfChar = 0 ;
62
- uint16_t frequency = 0 ;
63
- uint16_t duration = 0 ;
64
- uint8_t volume = 0 ;
65
-
66
- while (true )
67
- {
68
- while (Serial.available () != 0 ){Serial.read ();}
69
- Serial.println (F (" Enter a frequency in Hz (300-3400) or a DTMF character (0-9, *, #)" ));
70
- while (Serial.available () == 0 ){}
71
-
72
- inputString = Serial.readStringUntil (' \n ' );
73
-
74
- if (inputString.length () == 1 )
61
+ String inputString;
62
+ char dtmfChar = 0 ;
63
+ uint16_t frequency = 0 ;
64
+ uint16_t duration = 0 ;
65
+ uint8_t volume = 0 ;
66
+
67
+ while (true )
75
68
{
76
- dtmfChar = inputString.charAt (0 );
77
- if ((dtmfChar >= ' 0' && dtmfChar <= ' 9' ) || dtmfChar == ' *' || dtmfChar == ' #' )
78
- {
79
- break ;
80
- }
69
+ while (Serial.available () != 0 )
70
+ {
71
+ Serial.read ();
72
+ }
73
+ Serial.println (F (" Enter a frequency in Hz (300-3400) or a DTMF character (0-9, *, #)" ));
74
+ while (Serial.available () == 0 )
75
+ {
76
+ }
77
+
78
+ inputString = Serial.readStringUntil (' \n ' );
79
+
80
+ if (inputString.length () == 1 )
81
+ {
82
+ dtmfChar = inputString.charAt (0 );
83
+ if ((dtmfChar >= ' 0' && dtmfChar <= ' 9' ) || dtmfChar == ' *' || dtmfChar == ' #' )
84
+ {
85
+ break ;
86
+ }
87
+ }
88
+ else
89
+ {
90
+ frequency = inputString.toInt ();
91
+ if (frequency >= 300 && frequency <= 3400 )
92
+ {
93
+ dtmfChar == 0 ;
94
+ break ;
95
+ }
96
+ }
81
97
}
82
- else
98
+
99
+ while (true )
83
100
{
84
- frequency = inputString.toInt ();
85
- if (frequency >= 300 && frequency <= 3400 )
86
- {
87
- dtmfChar == 0 ;
88
- break ;
89
- }
101
+ while (Serial.available () != 0 )
102
+ {
103
+ Serial.read ();
104
+ }
105
+ Serial.println (F (" Enter a duration in ms (50-1360)" ));
106
+ while (Serial.available () == 0 )
107
+ {
108
+ }
109
+
110
+ inputString = Serial.readStringUntil (' \n ' );
111
+ duration = inputString.toInt ();
112
+ if (duration >= 50 && duration <= 1360 )
113
+ {
114
+ break ;
115
+ }
90
116
}
91
- }
92
-
93
- while (true )
94
- {
95
- while (Serial.available () != 0 ){Serial.read ();}
96
- Serial.println (F (" Enter a duration in ms (50-1360)" ));
97
- while (Serial.available () == 0 ){}
98
-
99
- inputString = Serial.readStringUntil (' \n ' );
100
- duration = inputString.toInt ();
101
- if (duration >= 50 && duration <= 1360 )
117
+
118
+ while (true )
102
119
{
103
- break ;
120
+ while (Serial.available () != 0 )
121
+ {
122
+ Serial.read ();
123
+ }
124
+ Serial.println (F (" Enter a volume (0-100)" ));
125
+ while (Serial.available () == 0 )
126
+ {
127
+ }
128
+
129
+ inputString = Serial.readStringUntil (' \n ' );
130
+ volume = inputString.toInt ();
131
+ if (volume <= 100 )
132
+ {
133
+ break ;
134
+ }
104
135
}
105
- }
106
-
107
- while (true )
108
- {
109
- while (Serial.available () != 0 ){Serial.read ();}
110
- Serial.println (F (" Enter a volume (0-100)" ));
111
- while (Serial.available () == 0 ){}
112
-
113
- inputString = Serial.readStringUntil (' \n ' );
114
- volume = inputString.toInt ();
115
- if (volume <= 100 )
136
+
137
+ if (dtmfChar == 0 )
138
+ {
139
+ myModule.generateToneFreq (frequency, duration, volume);
140
+ }
141
+ else
116
142
{
117
- break ;
143
+ myModule. generateToneDTMF (dtmfChar, duration, volume) ;
118
144
}
119
- }
120
-
121
- if (dtmfChar == 0 )
122
- {
123
- myModule.generateToneFreq (frequency, duration, volume);
124
- }
125
- else
126
- {
127
- myModule.generateToneDTMF (dtmfChar, duration, volume);
128
- }
129
145
}
0 commit comments