Would like to use the RobotBeep function. Do I need to add the entire Lib?

Brand new to this.

My sketch is being written for a UNO to provide control and audible alert functions in a communications device. The program will eventually be transferred to a stand alone on board MCU.

I would like to use the Robot.Beep function to provide audible alerts to the user under various conditions. I imported the Robot_Control library into my sketch and immediately got a ton of compile errors. Not knowing any better, I deleted everything except <ArduinoRobot.h>and added Robot.begin(); in Void setup() but got the same errors. (The learning area indicated that only the <ArduinoRobot.h> is necessary) however it appears that the Sound Library is also needed.

Can anyone help me out with this? I’ve attached a text file showing the compile errors. The only thing I need is the Beep function which I hope to use in a modified ‘blink without delay using two intervals’ manner to produce the beep(s) at preset intervals… a Beep Without Delay if you will that has an adjustable beep interval.

Thanks

Compile errors.txt (1.86 KB)

I don't think you can just delete portions of a library and expect it to compile. You have to write your own.

I initially imported the entire Robot_Control library into the sketch and it compiled with the same errors you see in the text file. They all showed as included in the sketch. Just can't see what I'm doing wrong.

So how much do you know about installing and using libraries ? You haven't posted your
code or a Notepad file of the compile errors so nobody here is going to be able to comment on the reason for your problem any time soon.

1- do you know where to install a library ?
2- do you know how to install a library ?
3- do you know how to copy the compiler VERBOSE output to a Notepad file ?
4- do you know WHAT VERBOSE output is ? (do you know how to select it?)
5- do you know HOW to post your code ?
6- WHY haven't you done it ?

Obviously, the answer to #1 & 2 is NO.

Ask me how I know that .

If all you want to do is "beep", can't you just use the tone() function? No need for a huge library then, unless the Robot Lib is doing something else for you.

@OP,
You should NOT install your libraries in the IDE libraries folder ! (THEY WILL NOT WORK THERE !)
Ask me WHERE you should install them.

This is the first sketch I've written. My original post has a text attachment with the compiler errors and I turned off VERBOSE to keep the file smaller. I didn't know if it was needed, I'll know better next time. So yes I do know how to do those things. I haven't posted the code yet because it was full of commented out experimental functions and the like which need to be cleaned out for legibility. (You've never been a teacher raschemmel...ask me how I know that). I'll post the sketch as soon as I can. Hopefully tomorrow.

I didn't install any libraries that weren't already in the IDE so that shouldn't be an issue. I'm simply trying to use the Robot_Control library that came with the IDE to get access to the Beep function. The desired library was added using #include following the directions in my tutorial. It didn't work so I came here for some help.

I'll learn quickly what's needed when posting but I can do without condescension thanks. The first steps of anything new is like drinking from a fire hose. It'll come, I've learned tougher stuff.

I'll get the sketch up here soon as I can. I apologize for the inexperience.

My sketch is being written for a UNO to provide control and audible alert functions in a communications device. The program will eventually be transferred to a stand alone on board MCU.

I would like to use the Robot.Beep function to provide audible alerts to the user under various conditions. I imported the Robot_Control library into my sketch and immediately got a ton of compile errors.

I imported the Robot_Control library into my sketch

What (EXACTLY) does this mean ? What did you do ? (what do you mean by “imported” ? as opposed to
"#included"or “installed” ?)

Post your code.

This is the BEEP sketch:

/*
 Beep
 
 Test different pre-configured beeps on
 the robot's speaker.

 Possible beeps are:
 - BEEP_SIMPLE
 - BEEP_DOUBLE
 - BEEP_LONG
 
 Circuit:
 * Arduino Robot
 
 created 1 May 2013
 by X. Yang
 modified 12 May 2013
 by D. Cuartielles
 
 This example is in the public domain
 */

#include <ArduinoRobot.h>

void setup() {
  // initialize the robot
  Robot.begin();

  // initialize the sound speaker
  Robot.beginSpeaker();
}
void loop() {
  Robot.beep(BEEP_SIMPLE);
  delay(1000);
  Robot.beep(BEEP_DOUBLE);
  delay(1000);
  Robot.beep(BEEP_LONG);
  delay(1000);
}

If all you want to do is have an audible BEEP, why are you going to all this trouble when you can use
the TONEAC Library ?

Here is the demo example modified to generate a single beep:

 // ---------------------------------------------------------------------------
// Connect your piezo buzzer (without internal oscillator) or speaker to these pins:
//   Pins  9 & 10 - ATmega328, ATmega128, ATmega640, ATmega8, Uno, Leonardo, etc.
//   Pins 11 & 12 - ATmega2560/2561, ATmega1280/1281, Mega
//   Pins 12 & 13 - ATmega1284P, ATmega644
//   Pins 14 & 15 - Teensy 2.0
//   Pins 25 & 26 - Teensy++ 2.0
// Be sure to include an inline 100 ohm resistor on one pin as you normally do when connecting a piezo or speaker.
// ---------------------------------------------------------------------------

#include <toneAC.h>

// Melody liberated from the toneMelody Arduino example sketch by Tom Igoe.
// int melody[] = { 262, 196, 196, 220, 196, 0, 247, 262 }; //
//int noteDurations[] = { 4 , 8, 8, 4, 4, 4, 4, 4}; //

void setup() {} // Nothing to setup, just start playing!

void loop()
{
 // for (unsigned long freq = 125; freq <= 15000; freq += 10) {  
  //  toneAC(freq); // Play the frequency (125 Hz to 15 kHz sweep in 10 Hz steps).
  //  delay(1);     // Wait 1 ms so you can hear it.
 // }
  //toneAC(); // Turn off toneAC, can also use noToneAC().

  delay(1000); // Wait a second.

  //for (int thisNote = 0; thisNote < 2; thisNote++) {

    int noteDuration = 1000;
    toneAC(300, 10, noteDuration, true); // Play thisNote at full volume for noteDuration in the  
                                                           // background.
    // delay(noteDuration * 4 / 3); // Wait while the tone plays in the background, plus another 33% delay 
    // between notes.
     //}


  while(1); // Stop (so it doesn't repeat forever driving you crazy--you're welcome).
}

And yes, i did test the ToneAC example I posted.

raschemmel thanks for the help, I appreciate it but please read the posts. I did use #include the same way you did in your example. I’ll post the code.

Again, I’ve never written a sketch before this so bear with me a bit. I studied for several weeks before starting and from what I understand using delay (and tone as well I think) stops anything else from happening in the sketch for the delay period. I need to monitor and respond to several conditions continuously without hesitations in the code.

I will post the code this morning.

Here’s the sketch so far. I’m trying to create a single beep every 3 minutes when PG = false and a double beep every 90 seconds when TXSEL = LOW. Both alerts subject to the boolean values of ‘discard’ and ‘noalerts’. (I could also use a single ‘discard’ value that would disregard any generated alert for the required times i.e always disregard or disregard for time = X. Cancel is a momentary switch and noalerts is ON/OFF).

For now I’d like to just get the required beep and double beep functions working. The entire Robot_Control library was imported here but I only need whats necessary for the beep to work which I believe is <ArduinoRobot.h>. …I think.

It’s important that the blink and audible alerts will run without interrupting other code functions. I’ve used Blink Without Delay to accomplish that and I’d like to use the same sort of function for the audible alert if possible. There can be no delay in selecting a transmitter position.

#include <ArduinoRobot.h>
#include <Arduino_LCD.h>
#include <Compass.h>
#include <EasyTransfer2.h>
#include <EEPROM_I2C.h>
#include <Fat16.h>
#include <Fat16Config.h>
#include <Fat16mainpage.h>
#include <Fat16util.h>
#include <FatStructs.h>
#include <Multiplexer.h>
#include <SdCard.h>
#include <SdInfo.h>
#include <Squawk.h>
#include <SquawkSD.h>


/*DTI sketch version 5.0.1
Control code for:
   - Bi-color power LED indication
   - Transmitter selection
   - Audible alerts of transmitter position
   - Audible low battery alert
   - Alert cancel and Alert off functions
*/

boolean firstcheck = true; //first check of the battery condition
boolean battchange = false; //remains false until PG indicates a change in battery status
boolean powergood = true;  //power supply is good
boolean discard = false; //discard any generated audible alert
boolean noalerts = false;  //alerts are selected on

#define ALERTOFF 13 
#define CANCEL 12
#define TXSEL 8
#define redLED 11 
#define greenLED 10
#define AUDTONE 3
#define SWCOMM 7
#define PG 4

//LED blink intervals 
#define LED_ON 400     //milliseconds
#define LED_OFF 3000

//
#define AUD_ON 2000    //milliseconds
#define AUD_OFF 5000

//for blink without delay functions
unsigned long ms;        //time from millis()
unsigned long msLast;    //last time the LED changed state
boolean ledState;        //current LED state

//for beep without delay functions
unsigned long msBeep;    //time from millis()
unsigned long msBeepLast;//
boolean audState;        //current audible state

void setup()
{
    pinMode(CANCEL, INPUT); //Cancel button input
    pinMode(ALERTOFF, INPUT); //To Alerts Off switch. Low = off
    pinMode(TXSEL, INPUT);  //To TXSEL switch. Low indicates COMM 2 selected
    pinMode(redLED, OUTPUT); //Power low indication
    pinMode(greenLED, OUTPUT); //Power good indication
    pinMode(SWCOMM, OUTPUT);//Output to selector IC. High = COMM 2
    pinMode(PG, INPUT); //Normally high, a low indicates poor battery
    pinMode(AUDTONE, OUTPUT); //PWM output pin
    Serial.begin(9600); // for debugging
    Robot.begin();
    Robot.beginSpeaker();

Here’s the error file

Arduino: 1.0.6 (Windows NT (unknown)), Board: "Arduino Uno"
C:\Program Files (x86)\Arduino\hardware\tools\avr\bin\avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=106 -IC:\Program Files (x86)\Arduino\hardware\arduino\cores\arduino -IC:\Program Files (x86)\Arduino\hardware\arduino\variants\standard -IC:\Program Files (x86)\Arduino\libraries\Robot_Control -IC:\Program Files (x86)\Arduino\libraries\Robot_Motor C:\Users\Kirk\AppData\Local\Temp\build6062083263277150311.tmp\DTI_5.0.1.cpp -o C:\Users\Kirk\AppData\Local\Temp\build6062083263277150311.tmp\DTI_5.0.1.cpp.o 

DTI_5.0.1.ino: In function 'void loop()':
DTI_5.0.1.ino:98: warning: suggest parentheses around assignment used as truth value
C:\Program Files (x86)\Arduino\libraries\Robot_Control/Fat16util.h: At global scope:
C:\Program Files (x86)\Arduino\libraries\Robot_Control/Fat16util.h:40: warning: 'int FreeRam()' defined but not used
C:\Program Files (x86)\Arduino\libraries\Robot_Control/Fat16util.h:70: warning: 'void SerialPrintln_P(const prog_char*)' defined but not used
C:\Program Files (x86)\Arduino\hardware\tools\avr\bin\avr-gcc -c -g -Os -Wall -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=106 -IC:\Program Files (x86)\Arduino\hardware\arduino\cores\arduino -IC:\Program Files (x86)\Arduino\hardware\arduino\variants\standard -IC:\Program Files (x86)\Arduino\libraries\Robot_Control -IC:\Program Files (x86)\Arduino\libraries\Robot_Motor -IC:\Program Files (x86)\Arduino\libraries\Robot_Control\utility C:\Program Files (x86)\Arduino\libraries\Robot_Control\glcdfont.c -o C:\Users\Kirk\AppData\Local\Temp\build6062083263277150311.tmp\Robot_Control\glcdfont.c.o 

C:\Program Files (x86)\Arduino\hardware\tools\avr\bin\avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=106 -IC:\Program Files (x86)\Arduino\hardware\arduino\cores\arduino -IC:\Program Files (x86)\Arduino\hardware\arduino\variants\standard -IC:\Program Files (x86)\Arduino\libraries\Robot_Control -IC:\Program Files (x86)\Arduino\libraries\Robot_Motor -IC:\Program Files (x86)\Arduino\libraries\Robot_Control\utility C:\Program Files (x86)\Arduino\libraries\Robot_Control\ArduinoRobot.cpp -o C:\Users\Kirk\AppData\Local\Temp\build6062083263277150311.tmp\Robot_Control\ArduinoRobot.cpp.o 

C:\Program Files (x86)\Arduino\libraries\Robot_Control\ArduinoRobot.cpp:3:18: error: Wire.h: No such file or directory
C:\Program Files (x86)\Arduino\libraries\Robot_Control\ArduinoRobot.cpp: In constructor 'RobotControl::RobotControl()':
C:\Program Files (x86)\Arduino\libraries\Robot_Control\ArduinoRobot.cpp:8: error: 'LCD_CS' was not declared in this scope
C:\Program Files (x86)\Arduino\libraries\Robot_Control\ArduinoRobot.cpp:8: error: 'DC_LCD' was not declared in this scope
C:\Program Files (x86)\Arduino\libraries\Robot_Control\ArduinoRobot.cpp:8: error: 'RST_LCD' was not declared in this scope
C:\Program Files (x86)\Arduino\libraries\Robot_Control\ArduinoRobot.cpp: In member function 'void RobotControl::begin()':
C:\Program Files (x86)\Arduino\libraries\Robot_Control\ArduinoRobot.cpp:13: error: 'Wire' was not declared in this scope
C:\Program Files (x86)\Arduino\libraries\Robot_Control\ArduinoRobot.cpp:18: error: 'MUXA' was not declared in this scope
C:\Program Files (x86)\Arduino\libraries\Robot_Control\ArduinoRobot.cpp:18: error: 'MUXB' was not declared in this scope
C:\Program Files (x86)\Arduino\libraries\Robot_Control\ArduinoRobot.cpp:18: error: 'MUXC' was not declared in this scope
C:\Program Files (x86)\Arduino\libraries\Robot_Control\ArduinoRobot.cpp:18: error: 'MUXD' was not declared in this scope
C:\Program Files (x86)\Arduino\libraries\Robot_Control\ArduinoRobot.cpp:19: error: 'MUX_IN' was not declared in this scope
C:\Program Files (x86)\Arduino\libraries\Robot_Control\ArduinoRobot.cpp:22: error: 'BUZZ' was not declared in this scope
C:\Program Files (x86)\Arduino\libraries\Robot_Control\ArduinoRobot.cpp:25: error: 'Serial1' was not declared in this scope

from what I understand using delay (and tone as well I think) stops anything else from happening in the sketch for the delay period.

NOT TRUE if you use millis()

READ THIS

If you are familiar with Blinkwithoutdelay then you know you can replace the delay() function in the TONEAC library with millis().

The entire Robot_Control library was imported here

What (EXACTLY) does this mean ? What did you do ? (what do you mean by "imported" ?

DEFINE "IMPORTED"

Where is the rest of your code ? (With all those libraries there has to be more code)

EXACTLY HOW did you copy the error code ? (did you use Control-A ?)

Do you know how to open the .cpp files listed in the error code ?

do you know where to find them ?
did you see the LINE #s ?

My area of expertise is NOT S/W but I am not convinced yet that your problem IS S/W. I still think you may be doing SOMETHING wrong but don't know yet because you are not telling me anything useful.

I need to know :

1-do you have a lot of experience installing libraries ?
2- where is your USER-installed library folder ?
(what is the EXACT PATH of it ?)
3- Do you know how to FIND your user library folder ?
4- Do you need the Robot Control library for anything OTHER than the BEEP ?
5-Have you turned ON VERBOSE output for the compiler and captured the ENTIRE compiler output ?
6-Do you know how to do that.

Please answer all of the above questions categorically.

I tried to show all the code the last time but it wouldn’t let me post. Said it was to many char. Here it is again. There isn’t a lot to it.

1-No I don’t have experience in this program, I’ve never written a sketch before, I fly airplanes.
2-I know the path to the lib folder C:\Users\Kirk\Documents\Arduino
3-If I know the path I know how to find it
3-Right now I only need the beep function of Robot_Control
4-Verbose is on, that’s all there is in the compiler output

The libraries were imported into the sketch using Sketch_Import Library on the sketch window toolbar. These are the built in libraries. If I want to install a new library I’ll use the Add Library.

1-Is this not the correct way to import a built in library into a sketch?
2-The imported libraries show as included but I’ve missed something because Robot.beep(Beep_Simple); doesn’t work.
3-Using TONEAC with millis() is what I’ve been thinking as well. Pin 11 output will be affected. I’ll need to move the led on that pin but yes that’s where I’m heading.
4-I’m here for help because I need to understand what I’ve done wrong with Robot_Control before moving on to using any other library. I’m sure it’s simple when you know how.

#include <ArduinoRobot.h>
#include <Arduino_LCD.h>
#include <Compass.h>
#include <EasyTransfer2.h>
#include <EEPROM_I2C.h>
#include <Fat16.h>
#include <Fat16Config.h>
#include <Fat16mainpage.h>
#include <Fat16util.h>
#include <FatStructs.h>
#include <Multiplexer.h>
#include <SdCard.h>
#include <SdInfo.h>
#include <Squawk.h>
#include <SquawkSD.h>


/*DTI sketch version 5.0.1
Control code for:
   - Bi-color power LED indication
   - Transmitter selection
   - Audible alerts of transmitter position
   - Audible low battery alert
   - Alert cancel and Alert off functions
*/

boolean firstcheck = true; //first check of the battery condition
boolean battchange = false; //remains false until PG indicates a change in battery status
boolean powergood = true;  //power supply is good
boolean discard = false; //discard any generated audible alert
boolean noalerts = false;  //alerts are selected on

#define ALERTOFF 13 
#define CANCEL 12
#define TXSEL 8
#define redLED 11 
#define greenLED 10
#define AUDTONE 3
#define SWCOMM 7
#define PG 4

//LED blink intervals 
#define LED_ON 400     //milliseconds
#define LED_OFF 3000

//
#define AUD_ON 2000    //milliseconds
#define AUD_OFF 5000

//for blink without delay functions
unsigned long ms;        //time from millis()
unsigned long msLast;    //last time the LED changed state
boolean ledState;        //current LED state

//for beep without delay functions
unsigned long msBeep;    //time from millis()
unsigned long msBeepLast;//
boolean audState;        //current audible state

void setup()
{
    pinMode(CANCEL, INPUT); //Cancel button input
    pinMode(ALERTOFF, INPUT); //To Alerts Off switch. Low = off
    pinMode(TXSEL, INPUT);  //To TXSEL switch. Low indicates COMM 2 selected
    pinMode(redLED, OUTPUT); //Power low indication
    pinMode(greenLED, OUTPUT); //Power good indication
    pinMode(SWCOMM, OUTPUT);//Output to selector IC. High = COMM 2
    pinMode(PG, INPUT); //Normally high, a low indicates poor battery
    pinMode(AUDTONE, OUTPUT); //PWM output pin
    Serial.begin(9600); // for debugging
    Robot.begin();
    Robot.beginSpeaker();
      
}

void loop()
{
  
/*Can't get it to compile so I don't know if this will work. Remove the included 
libraries and it compiles fine */

  Robot.beep(BEEP_SIMPLE);
  delay(1000);
  
     if (digitalRead(PG) == LOW)
     {
     powergood = false; //set the battery state 
     }
     else powergood = true;
     
  
Serial.print(powergood);

    if (powergood == true)//good battery
    {
      blinkgreenLED();
    }
    else  
      blinkredLED();
        
  if (powergood = false)
     
   {
     //call the single beep function here
     
     // put the following into the function
     if (msBeep - msBeepLast > (AUD_OFF))
     {
     analogWrite(AUDTONE, 150);
      delay(200);
      msBeepLast = msBeep;
      analogWrite (AUDTONE,0);
      }
   }
  {
 }
    
ms = millis();
msBeep = millis();
//Serial.print(msBeep);
 
}
//Blink without delay functions. All other code above this.
void blinkgreenLED(void)
  {
     //determine the last time the LED was on
    if (ms - msLast > (ledState ? LED_ON : LED_OFF)) 
    {
     //switch states if necessary
        digitalWrite(greenLED, ledState = !ledState);
        msLast = ms;
    }  
  }
void blinkredLED(void)
  {
    if (ms - msLast > (ledState ? LED_ON : LED_OFF)) 
    {
        digitalWrite(redLED, ledState = !ledState);
        msLast = ms;
       
    }
  }
  /*This section is being used to design beep functions
  without using delay if possible. Two functions, one for a 
  single beep, another for double beep. Both require 
  adjustable intervals*/
  /*
    This is stuff I was playing with

  void singleTone(void)
   {
   if (msBeep - msBeepLast > (AUD_OFF))
      {
      digitalWrite(AUDTONE, 300);
      analogWrite(AUDTONE, 300);
        msBeepLast = msBeep;
      }
     else analogWrite (AUDTONE, 0);
   }
  */

2-I know the path to the lib folder C:\Users\Kirk\Documents\Arduino
3-If I know the path I know how to find it

In the IDE , click File/Preferences and you'll see the path of your library

Yes I see the path. I just gave it to you in the last post.

Verbose is on, that’s all there is in the compiler output

My question was EXACTLY HOW did you copy the compiler output ?
I want to know where you moved the mouse, how you highlighted the text and how you
copied it. (every mouse click or motion)(I know you pasted it into Notepad. I want to know everything you did UP to that point .

For example, did you put the mouse over the compiler output window and DRAG it down to highlight it ?

No, I used the 'copy error to clipboard' button to the upper right of the compiler window. Then I pasted that in between the

markers.

I just deleted the Robot_Control lib and imported <Servo.h> to see if that would compile and it did. Could this be an error with the built in library?

Think I may see the problem. That last idea got me thinking. I did a quick search on the forum regarding problems with that library and it appears that it isn't compatible with 1.0.5. on windows 7. I'm running 1.0.6 on a Windows 8 platform. Could be the same issues.

So if that's the case? Would you suggest the TONEAC() and millis() approach to create;
1 - A single beep every 3 minutes and
2 - A double beep every 90 seconds as required subject to conditions 'discard' or 'off'?

Ideas?

Yes. (use the ToneAC lib.)
And that is (one of the) correct way(s) to copy the compiler output.
The other one is put the mouse cursor in the center of the window and Left click,
then hit Control-A to highlight, then Control-C to copy ,then Control-V to paste.

After thinking about it, I realized you don’t need a delay or millis() for the ToneAC code because it already
has a duration value. The processor will execute that for the given duration and move on to the next line of code. No delay necessary.

Look at this :
ToneAC library

Look at the example given. See the :

 toneAC(0); // Turn off toneAC, can also use noToneAC().

?

#include <toneAC.h>
 
void setup() {} // Nothing to setup, just start playing!
 
void loop() {
  for (unsigned long freq = 150; freq <= 15000; freq += 10){  
    toneAC(freq); // Play the frequency (150 Hz to 15 kHz).
    delay(1);     // Wait 1 ms so you can hear it.
  }
  toneAC(0); // Turn off toneAC, can also use noToneAC().
 
  while(1); // Stop.

Now look at this example I wrote:

// ---------------------------------------------------------------------------
// Connect your piezo buzzer (without internal oscillator) or speaker to these pins:
//   Pins  9 & 10 - ATmega328, ATmega128, ATmega640, ATmega8, Uno, Leonardo, etc.
//   Pins 11 & 12 - ATmega2560/2561, ATmega1280/1281, Mega
//   Pins 12 & 13 - ATmega1284P, ATmega644
//   Pins 14 & 15 - Teensy 2.0
//   Pins 25 & 26 - Teensy++ 2.0
// Be sure to include an inline 100 ohm resistor on one pin as you normally do when connecting a piezo or speaker.
// ---------------------------------------------------------------------------

#include <toneAC.h>
  unsigned long freq = 250;
  unsigned long time;
  unsigned long update;
  
void setup() 
 {
  Serial.begin(9600);
 } 

void loop() 
{
   time  = millis();
   Serial.print("Time: ");
   Serial.println(time);
   update = millis();
   Serial.println("Start tone ");
    while (update - time < 1000)
     {
       update = millis(); 
       toneAC(freq); // Play the frequency (125 Hz to 15 kHz sw
     }
     Serial.print("Update: ");
     Serial.println(update);
     Serial.println("Stop tone ");
     toneAC(0); // Turn off toneAC, can also use noToneAC().
     while(1); // Stop (so it doesn't repeat forever driving you crazy--you're welcome).
}

It turns out that if you don’t have something to tell the processor to stop playing the tone it just keeps playing it and if you don’t have a delay it stops playing it as soon as it executes the

toneAC(0);

code.
You need something to keep it playing the tone until the desired time has elapsed so I added the “while”
loop. It works perfectly.

Note; In YOUR program , the tone will be executed by a conditional, so the:
while(1) at the end of the program won’t be necessary. It was necessary for this example
because I don’t have a conditional to decide whether to play it or not.

Note the :

Pins 9 & 10 - ATmega328, ATmega128, ATmega640, ATmega8, Uno, Leonardo, etc.

Are these pins available ?