Cannot call member function without object

Hello, I saw TONS of arcticles on google and arduino forums about this issue, but I am a student and still learning so I didnt understand it. I am making an arduino library for sending IR signals to control an RGB strip.

Arduino Sketch:

#include <irforled.h>

void setup() {
  //patterns.basicpattern();
}

void loop() {
  // put your main code here, to run repeatedly:
patterns::basicpattern();
}

.cpp file

#include <irforled.h>

IRsend irsend;

<INSERT about 100 unsigned ints here>

int brightnessup= a1;
int brightnessdown= a2;
int play= a3;
int power= a4;
int red=a5;
int green=a6;
int blue=a7;
int white=a8;
int darkred=a9;
int lightgren=a10;
int blue2=a11;
int pink=a12;
int orange=a13;
int lightblue=a14;
int blackpurple=a15;
int lightpink=a16;
int lightyellow=a17;
int cyan=a18;
int blackpurple2=a19;
int lightlightblue=a20;
int darkyellow=a21;
int blue3=a22;
int lightpurple=a23;
int lightlightlightblue=a24;
int blindme=a36;

void patterns::basicpattern(void)
{
irsend.sendRaw(orange,68,38);
delay(100);
irsend.sendRaw(brightnessup,68,38);
irsend.sendRaw(brightnessup,68,38);
delay(100);
irsend.sendRaw(brightnessup,68,38);
irsend.sendRaw(brightnessup,68,38);
delay(100);
irsend.sendRaw(brightnessup,68,38);
irsend.sendRaw(brightnessup,68,38);
delay(100);
irsend.sendRaw(brightnessup,68,38);
irsend.sendRaw(brightnessup,68,38);
delay(100);
irsend.sendRaw(brightnessup,68,38);
irsend.sendRaw(brightnessup,68,38);
delay(100);
irsend.sendRaw(blue3,68,38);
delay(100);
irsend.sendRaw(brightnessdown,68,38);
irsend.sendRaw(brightnessdown,68,38);
delay(100);
irsend.sendRaw(brightnessdown,68,38);
irsend.sendRaw(brightnessdown,68,38);
delay(100);
irsend.sendRaw(brightnessdown,68,38);
irsend.sendRaw(brightnessdown,68,38);
delay(100);
irsend.sendRaw(brightnessdown,68,38);
irsend.sendRaw(brightnessdown,68,38);
delay(100);
irsend.sendRaw(brightnessdown,68,38);
irsend.sendRaw(brightnessdown,68,38);
delay(100); 
}

.h file

#ifndef irforled
#define irforled
 
#include <IRremote.h> 
#include <Arduino.h>
 
class irforled {
public:
      //  irforled();
     //   ~irforled();
       // void basicpattern();
    
};
class patterns {
 public:
 void basicpattern(void);
};
 
#endif

Whoa there.. What are you really trying to do? RECEIVE IR signals to control a LED strip? Or SEND them to something else to control the LED strip?

P.S. Karma point for using code tags on your first post.

-jim lee

jimLee: Whoa there.. What are you really trying to do? RECEIVE IR signals to control a LED strip? Or SEND them to something else to control the LED strip?

P.S. Karma point for using code tags on your first post.

-jim lee

Um.. thanks? Not sure what that is though.

Im sending IR codes. I know there are simpler ways probably.

You have to declare the method 'static' so it belongs to the Class, not an instance. Then, because it is a function of the Class, you can call it with ClassName::MethodName().

johnwasser: You have to declare the method 'static' so it belongs to the Class, not an instance. Then, because it is a function of the Class, you can call it with ClassName::MethodName().

Can you give me an example?

class ClassName {
  public:
  static void MethodName() { Serial.println(F("MethodeName")); }
};
void setup() {
  Serial.begin(250000);
  ClassName::MethodName();
}
void loop() {}

Why do you need to call a method without its object? I ask because you typically hold all the current state of your object in the object itself. Looking at your .cpp file it looks like you're storing a lot of information outside of your objects.

-jim lee

See my replies #5-#8 to this thread:

http://forum.arduino.cc/index.php?topic=452096.0

I define different flashing and fading sequences using objects that are constructed with parameters.

jimLee: Why do you need to call a method without its object? I ask because you typically hold all the current state of your object in the object itself. Looking at your .cpp file it looks like you're storing a lot of information outside of your objects.

-jim lee

The problem is I dont know what that means....

MaxAtStar: The problem is I dont know what that means....

Then it sounds like you really need to hit a few pages of learning before you start using classes. Those are all terms you need to understand. Google "C++ class" and see if you can't find a few good resources to help you understand how a class works and what it can and cannot do and when it should or should not be used.

MaxAtStar:
The problem is I dont know what that means…

That’s kinda’ what I was thinking.

class - blueprint for creating an object.

An object is like a self contained package of information including the instructions to manage itself. The instructions will include the methods that things outside the object (other objects, your program) can use to control the object.

So you are most likely trying to write a class that blinks an IR emitter in some way that your LED thing understands right?

If this i right, what kind of pattern is your LED thing expecting to see?

-jim lee

Suppose you have a class that defines what a Dog is. One thing that a Dog can do is bark.

You don't have a Dog, but you are trying to make it bark. How is that possible? Reasonable?

If you have a Dog, Fluffy, it can be hard to make the stupid thing shut up. But, without a Dog, barking isn't even possible.