Using library

Hey,

I am trying to use a library for a few days, but it does not run.

I am using Arduino 1.0.6. and an Arduino Uno R3.

The library (stored in ...\Documents\Arduino\libraries\LEDTools):

 #ifndef LEDTools_h
#define LEDTools_h

#include <Arduino.h>

class LEDTools {

public:
    void rgbToHsv(unsigned char r, unsigned char g, unsigned char b);
     

};
#include "LEDTools.h"

void LEDTools::rgbToHsv(unsigned char r, unsigned char g, unsigned char b) {
    double rd = (double) r/255;
    double gd = (double) g/255;
    double bd = (double) b/255;
    double max = max(rd, max(gd, bd)), min = min(rd, min(gd, bd));
    double h, s, v = max;

    double d = max - min;
    s = max == 0 ? 0 : d / max;

    if (max == min) { 
        h = 0;
    } else {
        if (max == rd) {
            h = (gd - bd) / d + (gd < bd ? 6 : 0);
        } else if (max == gd) {
            h = (bd - rd) / d + 2;
        } else if (max == bd) {
            h = (rd - gd) / d + 4;
        }
        h /= 6;
    }

   
}

Arduino Code:

#include <LEDTools.h>

void setup() {
  // put your setup code here, to run once:
}

byte r,b,g = 1;

void loop() {
  
  rgbToHsv( r, b, g );
}

Error message:

test.ino: In function 'void loop()':
test:11: error: 'rgbToHsv' was not declared in this scope

Please, help me :cry:

Try

LEDTools.rgbToHsv( r, b, g );

Thanks for the reply, but it is not working:

test.ino: In function 'void loop()':
test:14: error: expected unqualified-id before '.' token

Try then

#ifndef LEDTools_h
#define LEDTools_h

#include <Arduino.h>

class LEDTools {

public:
    
    LEDTools() {unsigned char r,g,b;}  //constructor

    void rgbToHsv(unsigned char r, unsigned char g, unsigned char b);

     

};
LEDTools newLed;

And then on loop

newLed.rgbToHsv(r,g,b);

Tell us if there's any error, I'm not an expert on classes and programming.

Edit: Also I forgot to add the construction declaration on the .h.

Ok, it worked, thank you :slight_smile:

But I still wonder why it is not working as a library, maybe somebody has a clue?