Pages: [1]   Go Down
Author Topic: Errors Creating Library  (Read 980 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Sr. Member
****
Karma: 7
Posts: 476
what?
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,
I know im being an idiot here and the answers probably simple but i cannot see it, im trying to tidy up my sketch by creating a library so here goes with just one of the functions using Morse example as a guide.
Code:
/*
      UC1608.h       LCD Library for 240x128 Pannel
      using UC1608 controller.
      Created by S. Ruscoe 15/2/2010
*/

#include "WProgram.h"

#ifndef uc1608_h
#define uc1608_h

class UC1608
{
      public:
            void setbacklight(int Rval, int Gval, int Bval);
      private:
            int _Rval;
            int _Gval;
            int _Bval;
};

#endif

And the Cpp file reads
Code:
/*
      UC1608.cpp LCD Library for 240x128 Pannel
      using UC1608 controller.
      Created by S. Ruscoe 15/2/2010
*/

#include "WProgram.h"
#include "uc1608.h"

int Rled = 9;    // Red Backlight digital pin 9
int Gled = 10;   // Green Backlight digital pin 10
int Bled = 11;   // Blue Backlight digital pin 11  

void UC1608::setbacklight(int Rval, int Gval, int Bval)
{

       analogWrite(Rled, _Rval);
        analogWrite(Gled, _Gval);
        analogWrite(Bled, _Bval);      
      _Rval = Rval;
      _Gval = Gval;
      _Bval = Bval;
}

in my sketch
Code:
UC1608.setbacklight(0,0,128);
Gives - In function 'void setup()':
error: expected unqualified-id before '.' token

or
Code:
UC1608 setbacklight(0,0,128);

Gives - In function 'void setup()':
error: no matching function for call to 'UC1608::UC1608(int, int, int)'C:\arduino-0018\libraries\UC1608/uc1608.h:14: note: candidates are: UC1608::UC1608()

C:\arduino-0018\libraries\UC1608/uc1608.h:14: note:                 UC1608::UC1608(const UC1608&)

What am i doing wrong? Please

Thanks
Logged

Norway@Oslo
Offline Offline
Edison Member
*
Karma: 12
Posts: 2033
loveArduino(true);
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Try
Code:
UC1608 uc1608;
uc1608.setbacklight(0,0,128);
Logged

0
Offline Offline
Sr. Member
****
Karma: 7
Posts: 476
what?
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thankyou AlphaBeta,
i guess thats the reason your a god member and im not.
what difference does this make
Code:
UC1608 uc1608;
uc1608.setbacklight(0,0,128);
it killed the errors anyhow, but the code still didn't work, out of interest i deleted refrences to       
Code:
int _Rval;
int _Gval;
int _Bval;
     
and now it does
thanks again
Logged

Norway@Oslo
Offline Offline
Edison Member
*
Karma: 12
Posts: 2033
loveArduino(true);
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Well. The difference between the two UC1608 and uc1608 is that UC1608 is the name of the class (or library) and uc1608 is the name of an instance of the class.

UC1608 is like the recipe, and uc1608 is like the product. You can not ask a recipe for anything other than how to create something, but you can ask the object which is created to do something.

Note that the name uc1608 was just an example.
Code:
UC1608 anotherExample; //construct an object from the class (recipe) UC1608
anotherExample.setbacklight(0,0,128);
smiley
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
      analogWrite(Rled, _Rval);
        analogWrite(Gled, _Gval);
        analogWrite(Bled, _Bval);
      _Rval = Rval;
      _Gval = Gval;
      _Bval = Bval;

You are using the values in _Rval, _Gval, and _Bval before assigning the input values to them. Is that intentional?
Logged

0
Offline Offline
Sr. Member
****
Karma: 7
Posts: 476
what?
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks,
I think i get it Alphabeta but im a few ingredients short of the recipe, learning something new everyday.

PaulS, i've taken the _Rval, GVal......  references out now but i see what your saying.


Logged

Pages: [1]   Go Up
Jump to: