Skip to content

Format library #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
226 changes: 121 additions & 105 deletions examples/Audio_Examples/AudioExample1_PlayTone/AudioExample1_PlayTone.ino
Original file line number Diff line number Diff line change
Expand Up @@ -6,124 +6,140 @@

// Uncomment the module you're using. If your module is not listed below, then
// it's not supported for this example
UBX_CELL_VOICE_BASE myModule; // This example works with all voice-enabled modules, so this base class can be used
// LARA_R6001 myModule;
// LARA_R6401 myModule;
// LARA_R6801_00B myModule;
SparkFun_ublox_Cellular_Voice myModule; // This example works with all voice-enabled modules, so this base class can be used
// SparkFun_ublox_LARA_R6001 myModule;
// SparkFun_ublox_LARA_R6401 myModule;
// SparkFun_ublox_LARA_R6801_00B myModule;

void setup()
{
Serial.begin(115200); // Start the serial console

// Wait for user to press key to begin
Serial.println(F("u-blox Cellular Audio Example 1 - Play Tone"));

Serial.println();
Serial.println(F("! ! ! ! ! ATTENTION ! ! ! ! ! ATTENTION ! ! ! ! ! ATTENTION ! ! ! ! !"));
Serial.println(F("This example requires an audio codec attached to the I2S interface"));
Serial.println(F("of the cellular modem. Please add one and update this example as"));
Serial.println(F("needed to configure your audio codec!"));
Serial.println(F("! ! ! ! ! ATTENTION ! ! ! ! ! ATTENTION ! ! ! ! ! ATTENTION ! ! ! ! !"));
Serial.println();

Serial.println(F("Press any key to begin"));

while (!Serial.available()) // Wait for the user to press a key (send any serial character)
;
while (Serial.available()) // Empty the serial RX buffer
Serial.read();

Serial.println(F("Beginning..."));

// myModule.enableDebugging(); // Uncomment this line to enable helpful debug messages on Serial

// For the MicroMod Asset Tracker, we need to invert the power pin so it pulls high instead of low
// Uncomment the next line if required
// myModule.invertPowerPin(true);

// Initialize the module
if (myModule.begin(mySerial, UBX_CELL_DEFAULT_BAUD_RATE) )
{
Serial.println(F("Module connected!"));
}
else
{
Serial.println(F("Unable to communicate with the module."));
Serial.println(F("Manually power-on (hold the module's On button for 3 seconds) and try again."));
while (1) ; // Loop forever on fail
}
Serial.println();
Serial.begin(115200); // Start the serial console

// Wait for user to press key to begin
Serial.println(F("u-blox Cellular Audio Example 1 - Play Tone"));

Serial.println();
Serial.println(F("! ! ! ! ! ATTENTION ! ! ! ! ! ATTENTION ! ! ! ! ! ATTENTION ! ! ! ! !"));
Serial.println(F("This example requires an audio codec attached to the I2S interface"));
Serial.println(F("of the cellular modem. Please add one and update this example as"));
Serial.println(F("needed to configure your audio codec!"));
Serial.println(F("! ! ! ! ! ATTENTION ! ! ! ! ! ATTENTION ! ! ! ! ! ATTENTION ! ! ! ! !"));
Serial.println();

Serial.println(F("Press any key to begin"));

while (!Serial.available()) // Wait for the user to press a key (send any serial character)
;
while (Serial.available()) // Empty the serial RX buffer
Serial.read();

Serial.println(F("Beginning..."));

// myModule.enableDebugging(); // Uncomment this line to enable helpful debug messages on Serial

// For the MicroMod Asset Tracker, we need to invert the power pin so it pulls high instead of low
// Uncomment the next line if required
// myModule.invertPowerPin(true);

// Initialize the module
if (myModule.begin(mySerial, UBX_CELL_DEFAULT_BAUD_RATE))
{
Serial.println(F("Module connected!"));
}
else
{
Serial.println(F("Unable to communicate with the module."));
Serial.println(F("Manually power-on (hold the module's On button for 3 seconds) and try again."));
while (1)
; // Loop forever on fail
}
Serial.println();
}

void loop()
{
String inputString;
char dtmfChar = 0;
uint16_t frequency = 0;
uint16_t duration = 0;
uint8_t volume = 0;

while(true)
{
while(Serial.available() != 0){Serial.read();}
Serial.println(F("Enter a frequency in Hz (300-3400) or a DTMF character (0-9, *, #)"));
while(Serial.available() == 0){}

inputString = Serial.readStringUntil('\n');

if(inputString.length() == 1)
String inputString;
char dtmfChar = 0;
uint16_t frequency = 0;
uint16_t duration = 0;
uint8_t volume = 0;

while (true)
{
dtmfChar = inputString.charAt(0);
if((dtmfChar >= '0' && dtmfChar <= '9') || dtmfChar == '*' || dtmfChar == '#')
{
break;
}
while (Serial.available() != 0)
{
Serial.read();
}
Serial.println(F("Enter a frequency in Hz (300-3400) or a DTMF character (0-9, *, #)"));
while (Serial.available() == 0)
{
}

inputString = Serial.readStringUntil('\n');

if (inputString.length() == 1)
{
dtmfChar = inputString.charAt(0);
if ((dtmfChar >= '0' && dtmfChar <= '9') || dtmfChar == '*' || dtmfChar == '#')
{
break;
}
}
else
{
frequency = inputString.toInt();
if (frequency >= 300 && frequency <= 3400)
{
dtmfChar == 0;
break;
}
}
}
else

while (true)
{
frequency = inputString.toInt();
if(frequency >= 300 && frequency <= 3400)
{
dtmfChar == 0;
break;
}
while (Serial.available() != 0)
{
Serial.read();
}
Serial.println(F("Enter a duration in ms (50-1360)"));
while (Serial.available() == 0)
{
}

inputString = Serial.readStringUntil('\n');
duration = inputString.toInt();
if (duration >= 50 && duration <= 1360)
{
break;
}
}
}

while(true)
{
while(Serial.available() != 0){Serial.read();}
Serial.println(F("Enter a duration in ms (50-1360)"));
while(Serial.available() == 0){}

inputString = Serial.readStringUntil('\n');
duration = inputString.toInt();
if(duration >= 50 && duration <= 1360)

while (true)
{
break;
while (Serial.available() != 0)
{
Serial.read();
}
Serial.println(F("Enter a volume (0-100)"));
while (Serial.available() == 0)
{
}

inputString = Serial.readStringUntil('\n');
volume = inputString.toInt();
if (volume <= 100)
{
break;
}
}
}

while(true)
{
while(Serial.available() != 0){Serial.read();}
Serial.println(F("Enter a volume (0-100)"));
while(Serial.available() == 0){}

inputString = Serial.readStringUntil('\n');
volume = inputString.toInt();
if(volume <= 100)

if (dtmfChar == 0)
{
myModule.generateToneFreq(frequency, duration, volume);
}
else
{
break;
myModule.generateToneDTMF(dtmfChar, duration, volume);
}
}

if(dtmfChar == 0)
{
myModule.generateToneFreq(frequency, duration, volume);
}
else
{
myModule.generateToneDTMF(dtmfChar, duration, volume);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,66 +6,77 @@

// Uncomment the module you're using. If your module is not listed below, then
// it's not supported for this example
UBX_CELL_VOICE_BASE myModule; // This example works with all voice-enabled modules, so this base class can be used
// LARA_R6001 myModule;
// LARA_R6401 myModule;
// LARA_R6801_00B myModule;
SparkFun_ublox_Cellular_Voice myModule; // This example works with all voice-enabled modules, so this base class can be used
// SparkFun_ublox_LARA_R6001 myModule;
// SparkFun_ublox_LARA_R6401 myModule;
// SparkFun_ublox_LARA_R6801_00B myModule;

void setup()
{
Serial.begin(115200); // Start the serial console
Serial.begin(115200); // Start the serial console

// Wait for user to press key to begin
Serial.println(F("u-blox Cellular Audio Example 2 - Loopback"));
// Wait for user to press key to begin
Serial.println(F("u-blox Cellular Audio Example 2 - Loopback"));

Serial.println();
Serial.println(F("! ! ! ! ! ATTENTION ! ! ! ! ! ATTENTION ! ! ! ! ! ATTENTION ! ! ! ! !"));
Serial.println(F("This example requires an audio codec attached to the I2S interface"));
Serial.println(F("of the cellular modem. Please add one and update this example as"));
Serial.println(F("needed to configure your audio codec!"));
Serial.println(F("! ! ! ! ! ATTENTION ! ! ! ! ! ATTENTION ! ! ! ! ! ATTENTION ! ! ! ! !"));
Serial.println();
Serial.println();
Serial.println(F("! ! ! ! ! ATTENTION ! ! ! ! ! ATTENTION ! ! ! ! ! ATTENTION ! ! ! ! !"));
Serial.println(F("This example requires an audio codec attached to the I2S interface"));
Serial.println(F("of the cellular modem. Please add one and update this example as"));
Serial.println(F("needed to configure your audio codec!"));
Serial.println(F("! ! ! ! ! ATTENTION ! ! ! ! ! ATTENTION ! ! ! ! ! ATTENTION ! ! ! ! !"));
Serial.println();

Serial.println(F("Press any key to begin"));

while (!Serial.available()) // Wait for the user to press a key (send any serial character)
;
while (Serial.available()) // Empty the serial RX buffer
Serial.read();
Serial.println(F("Press any key to begin"));

Serial.println(F("Beginning..."));
while (!Serial.available()) // Wait for the user to press a key (send any serial character)
;
while (Serial.available()) // Empty the serial RX buffer
Serial.read();

// myModule.enableDebugging(); // Uncomment this line to enable helpful debug messages on Serial
Serial.println(F("Beginning..."));

// For the MicroMod Asset Tracker, we need to invert the power pin so it pulls high instead of low
// Uncomment the next line if required
// myModule.invertPowerPin(true);
// myModule.enableDebugging(); // Uncomment this line to enable helpful debug messages on Serial

// Initialize the module
if (myModule.begin(mySerial, UBX_CELL_DEFAULT_BAUD_RATE) )
{
Serial.println(F("Module connected!"));
}
else
{
Serial.println(F("Unable to communicate with the module."));
Serial.println(F("Manually power-on (hold the module's On button for 3 seconds) and try again."));
while (1) ; // Loop forever on fail
}
Serial.println();
// For the MicroMod Asset Tracker, we need to invert the power pin so it pulls high instead of low
// Uncomment the next line if required
// myModule.invertPowerPin(true);

// Initialize the module
if (myModule.begin(mySerial, UBX_CELL_DEFAULT_BAUD_RATE))
{
Serial.println(F("Module connected!"));
}
else
{
Serial.println(F("Unable to communicate with the module."));
Serial.println(F("Manually power-on (hold the module's On button for 3 seconds) and try again."));
while (1)
; // Loop forever on fail
}
Serial.println();
}

void loop()
{
while(Serial.available() != 0){Serial.read();}
Serial.println(F("Enter any key to begin loopback"));
while(Serial.available() == 0){}

myModule.playAudioResource(UBX_CELL_AUDIO_RESOURCE_LOOPBACK);

while(Serial.available() != 0){Serial.read();}
Serial.println(F("Enter any key to stop loopback"));
while(Serial.available() == 0){}

myModule.stopAudioResource(UBX_CELL_AUDIO_RESOURCE_LOOPBACK);
while (Serial.available() != 0)
{
Serial.read();
}
Serial.println(F("Enter any key to begin loopback"));
while (Serial.available() == 0)
{
}

myModule.playAudioResource(UBX_CELL_AUDIO_RESOURCE_LOOPBACK);

while (Serial.available() != 0)
{
Serial.read();
}
Serial.println(F("Enter any key to stop loopback"));
while (Serial.available() == 0)
{
}

myModule.stopAudioResource(UBX_CELL_AUDIO_RESOURCE_LOOPBACK);
}
Loading