Library containing analogReadResolution and analogWriteResolution?

When calling analogReadResolution or analogWriteResolution in arduino IDE, I get no errors. Probably cause it automatically includes it's library. But when I try to use it in my own library I get an error. Even tho I did included "arduino.h". Does this mean it has a specific library? And If so how is it called and where is it?

what does the error message say

could you post your library nb: use code tags

In the reference manual is says those two functions are for "Zero, Due & MKR Family". You have to select one of those board for those functions to be defined.

Test Library that I import into my sketch and get an error.

#ifndef TestLib_h
#define TestLib_h

#include "arduino.h"

analogReadResolution(12);

#endif

Error: TestLib.h:6:21: error: expected constructor, destructor, or type conversion before '(' token Note that if I don't include "arduino.h" I get the same error.

johnwasser: In the reference manual is says those two functions are for "Zero, Due & MKR Family". You have to select one of those board for those functions to be defined.

I did select Due as my board. That is not a problem.

I repeat, This code has no errors in IDE, but it does in my library

That code will give the same error in a sketch in the Arduino IDE. The problem is you're calling a function from the global scope. You can't do that. Being in a library makes no difference.

Compile this sketch in the Arduino IDE to verify what I'm saying:

analogReadResolution(12);
void setup() {}
void loop() {}

WoRRaDeR99: ```

include "arduino.h"

The correct filename is Arduino.h. Incorrect file name case will cause compilation of your library to fail on a file name case sensitive OS like Linux.

My library is compiling the same with "arduino.h" and "Arduino.h"

When I put it in void function. I get the same error

#ifndef TestLib_h
#define TestLib_h

#include "Arduino.h"

void test {
    analogReadResolution(12);
};

#endif

Your 'test' is not a function because you forgot to put '()' after the name.

#ifndef TestLib_h
#define TestLib_h

#include "Arduino.h"

void test() {
    analogReadResolution(12);
}

#endif

Does not matter, same error... :(

WoRRaDeR99: My library is compiling the same with "arduino.h" and "Arduino.h"

That's because you're using a filename case insensitive operating system. Usually when people make the effort to write a library, they are intending to share their code with others. Sharing code that only runs on certain OS cases a lot of confusion and frustration. I have seen this happen many times. It's best just to write the code correctly from the start. Even on file name case insensitive OS, you still need to use the correct file name case in your sketches, so it's best to get into the habit of doing it right anyway.

WoRRaDeR99: Does not matter, same error... :(

Works for me. Are you sure you saved your changes to the library file?

When you encounter an error you'll see a button on the right side of the orange bar "Copy error messages". Click that button. Paste the error in a message here using code tags.

With this sketch:

#include "Gio_TestLib.h"

void setup() {
}

void loop() {
}

And this library:

#ifndef TestLib_h
#define TestLib_h

#include "Arduino.h"

void test() {
    analogReadResolution(12);
}

#endif

When compiling my sketch I get This error(too long so I cut just the last part):

In file included from C:\Users\Owner\Documents\Arduino\saves\TestSketch\TestSketch.ino:1:0:

C:\Users\Owner\Documents\Arduino\libraries\Gio_TestLib/Gio_TestLib.h:6:21: error: expected constructor, destructor, or type conversion before '(' token

 analogReadResolution(12);

                     ^

Using library Gio_TestLib in folder: C:\Users\Owner\Documents\Arduino\libraries\Gio_TestLib (legacy)
exit status 1
Error compiling for board Arduino Due (Programming Port).

Works for me. Your error message doesn't match your code:

WoRRaDeR99: C:\Users\Owner\Documents\Arduino\libraries\Gio_TestLib/Gio_TestLib.h:6:21: error: expected constructor, destructor, or type conversion before '(' token

analogReadResolution(12);

That says the code is at line 6. However, in the latest library code you posted it's at line 7. In your original buggy code that line is at line 6: http://forum.arduino.cc/index.php?topic=587060.msg3993838#msg3993838 So I think you're not saving your changes to the library file at C:\Users\Owner\Documents\Arduino\libraries\Gio_TestLib\Gio_TestLib.h.

Oh... Damn... Seems like I truly did not save my file... Tnx

Just one little question... Can I make call analogReadResolution() somehow inside my library? As in make it run without the need to call a function from my sketch?

I'm glad to hear it's working now!

Can I make call analogReadResolution() somehow inside my library? As in make it run without the need to call a function from my sketch?

Not really. Think of a library as a collection of related functions. The usual way to do something like this is to add a begin() function, which runs all the initialization code for the library. The user is required to always call that function before they use the library. You'll be familiar with that paradigm from many other common Arduino libraries.

WoRRaDeR99: Just one little question... Can I make call analogReadResolution() somehow inside my library? As in make it run without the need to call a function from my sketch?

If your library sets the analog read resolution can I presume that somewhere in your library is a call to analogRead()? If so, just set the resolution in that code, anywhere before you actually call analogRead(). If your library contains no code, why do you want to set the analog read resolution?