1
+ #include " SparkFun_u-blox_Cellular_Arduino_Library.h"
2
+
3
+ // Uncomment the line below that you need for Serial on your platform
4
+ #define mySerial Serial1
5
+ // SoftwareSerial mySerial(16, 17);
6
+
7
+ // Uncomment the module you're using. If your module is not listed below, then
8
+ // it's not supported for this example
9
+ UBX_CELL_VOICE_BASE myModule; // This example works with all voice-enabled modules, so this base class can be used
10
+ // LARA_R6001 myModule;
11
+ // LARA_R6401 myModule;
12
+ // LARA_R6801_00B myModule;
13
+
14
+ void setup ()
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
+ Serial.println (F (" Press any key to begin" ));
21
+
22
+ while (!Serial.available ()) // Wait for the user to press a key (send any serial character)
23
+ ;
24
+ while (Serial.available ()) // Empty the serial RX buffer
25
+ Serial.read ();
26
+
27
+ Serial.println (F (" Beginning..." ));
28
+
29
+ // myModule.enableDebugging(); // Uncomment this line to enable helpful debug messages on Serial
30
+
31
+ // For the MicroMod Asset Tracker, we need to invert the power pin so it pulls high instead of low
32
+ // Uncomment the next line if required
33
+ // myModule.invertPowerPin(true);
34
+
35
+ // Initialize the module
36
+ if (myModule.begin (mySerial, UBX_CELL_DEFAULT_BAUD_RATE) )
37
+ {
38
+ Serial.println (F (" Module connected!" ));
39
+ }
40
+ else
41
+ {
42
+ Serial.println (F (" Unable to communicate with the module." ));
43
+ Serial.println (F (" Manually power-on (hold the module's On button for 3 seconds) and try again." ));
44
+ while (1 ) ; // Loop forever on fail
45
+ }
46
+ Serial.println ();
47
+ }
48
+
49
+ void loop ()
50
+ {
51
+ String inputString;
52
+ char dtmfChar = 0 ;
53
+ uint16_t frequency = 0 ;
54
+ uint16_t duration = 0 ;
55
+ uint8_t volume = 0 ;
56
+
57
+ while (true )
58
+ {
59
+ while (Serial.available () != 0 ){Serial.read ();}
60
+ Serial.println (F (" Enter a frequency in Hz (300-3400) or a DTMF character (0-9, *, #)" ));
61
+ while (Serial.available () == 0 ){}
62
+
63
+ inputString = Serial.readStringUntil (' \n ' );
64
+
65
+ if (inputString.length () == 1 )
66
+ {
67
+ dtmfChar = inputString.charAt (0 );
68
+ if ((dtmfChar >= ' 0' && dtmfChar <= ' 9' ) || dtmfChar == ' *' || dtmfChar == ' #' )
69
+ {
70
+ break ;
71
+ }
72
+ }
73
+ else
74
+ {
75
+ frequency = inputString.toInt ();
76
+ if (frequency >= 300 && frequency <= 3400 )
77
+ {
78
+ dtmfChar == 0 ;
79
+ break ;
80
+ }
81
+ }
82
+ }
83
+
84
+ while (true )
85
+ {
86
+ while (Serial.available () != 0 ){Serial.read ();}
87
+ Serial.println (F (" Enter a duration in ms (50-1360)" ));
88
+ while (Serial.available () == 0 ){}
89
+
90
+ inputString = Serial.readStringUntil (' \n ' );
91
+ duration = inputString.toInt ();
92
+ if (duration >= 50 && duration <= 1360 )
93
+ {
94
+ break ;
95
+ }
96
+ }
97
+
98
+ while (true )
99
+ {
100
+ while (Serial.available () != 0 ){Serial.read ();}
101
+ Serial.println (F (" Enter a volume (0-100)" ));
102
+ while (Serial.available () == 0 ){}
103
+
104
+ inputString = Serial.readStringUntil (' \n ' );
105
+ volume = inputString.toInt ();
106
+ if (volume <= 100 )
107
+ {
108
+ break ;
109
+ }
110
+ }
111
+
112
+ if (dtmfChar == 0 )
113
+ {
114
+ myModule.generateToneFreq (frequency, duration, volume);
115
+ }
116
+ else
117
+ {
118
+ myModule.generateToneDTMF (dtmfChar, duration, volume);
119
+ }
120
+ }
0 commit comments