Can a library decare variables that can be used by the actual program?

Hello,

I'm new to Arduino, and I am trying to design a library that makes creating tunes to be used by a piezo easier. And i am trying to define variables in the library, that can be used in the program, for example:

#define NOTE_C 33

The above variable above is declared in the libraries .cpp file.

Can this variable be used in this manner(from the actual arduino file, not the libraries files)?:

void loop(){
  note = NOTE_C;
}

I have been attempting to get this to work all day and I have not found any useful information.

First, a #define preprocessor directive as you have used it does not declare or define a variable. Always remember that a #define is a textual replacement in the source code...that's all. Also, symbolic constants are usually defined in the header file (.h), not the .cpp file.

For your code fragment to have any hope of working, you need to define a variable named note in your code. I'll assume you need to use an int data type and the associated header file PlayNote.h contains the #define directive. So, you might use:

#include "PlayNote.h"

void setup() {
   /// whatever statements you need...
}

void loop(){
  int note = NOTE_C;   // You now have a variable named note that is initialized to 33

  // more statements...
}

Thank you very much. My library now works flawlessly.

And thank you for clarifying "#define" for me also, Iresearched it additionally to know what a "preprocessor directive" is.

Thank you again.