Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [class]

A custom structure in C++ (and various other languages) which can contain member data and functions. An instance of a class is called an object.

1
vote
3answers
398 views

Why to store a function parameter value in a class private variable?

I'm just curious, I'm going through a C++ library for the mcu2.4 TFT display. And this method I notice when I run through C++ libraries. Which is when a parameter is passed through a function, it's ...
1
vote
1answer
36 views

Sketch with multiple classes (.h and .cpp) - how to interconnect classes

I wanted to move most functionality of my sketch into different classes, to keep things better organized. One class worked just fine, but when I had to use multiple classes and pass information ...
0
votes
1answer
105 views

Passing HardwareSerial and SoftwareSerial as a Class Property

I wish to know if there is a way to use a single property Serial0 to hold a HardwareSerial or a SoftwareSerial or other class instances supporting basic methods such as available(), read() and write(),...
2
votes
1answer
473 views

C++ Undefined reference to 'Class:Function()'

I have these files: Project.ino Sensor.h Sensor.cpp IMU/L3G.h IMU/L3G.cpp Sensor.h #ifndef Sensor_h #define Sensor_h #include <EEPROM.h> #include "IMU/L3G.h" #define CUTOFF_FREQ 30 #define ...
-1
votes
1answer
84 views

Factory Pattern on Arduino

I'm looking to create a factory pattern to identify which of N objects is attached to my Serial port. Assuming each object has a unique response to the input stream "What topic is this?", How can I ...
2
votes
2answers
288 views

Arduino Libraries: Declaring variables as public?

How come I never see any Arduino Library expose some of it's internal variables as public in the header file? I only see functions which are declared as public, while every variable is declared ...
0
votes
1answer
101 views

Passing reference to hardware between methods in custom class

I'm a C++ / Arduino newbie, trying to build a custom library for the first time. I created a unit called CDSensors.cpp, which has two methods, SetupSensor and ReadSensors. The sensor is a SparkFun ...
0
votes
1answer
54 views

Is there any way to group variables like group.variable as you can in Java/Delphi

I'm writing a sketch which does some calculations on measured variables, and it's based on a similar program written in Java like c = A.Ux + B.Uz; Where A&B have various parameters Ux,Uy,Uz etc In ...
0
votes
0answers
21 views

How use an interrupt function defined inside a class [duplicate]

I want to define only one interrupt function inside a class and then initialize this class with pin number. This is the Arduino sketch: #include <EnableInterrupt.h> class PinTouch { int pin;...
1
vote
1answer
89 views

Initializing an array within a class

I'm making a game of snake on the adafruit Neopixel shield and have run in to a problem. How do you fill out an array (in this case a 5*8 array) with values once the class has been called. This is my ...
0
votes
2answers
415 views

Arduino Interrupts Classes and Namespace

I'm working inside the Arduino IDE environment and have made a class that builds on the Adafruit RDG LCD with interrupts While looking at how to combine the Attach Interrupt() into my class I came ...
1
vote
1answer
311 views

Templated class: How to create instance and work with it?

I have created a class like this: #ifndef MyList_h #define MyList_h #include "Arduino.h" template <typename T> class MyList { public: MyList(void); ~MyList(void); void addItem(T* ...
1
vote
2answers
429 views

Function, struct or class?

I am trying to learn more about arduino programming, and recently i've written functions for randomizing and then modifying a single array. Now i'd like to do the same for four individual arrays. This ...
2
votes
1answer
93 views

LED fade class strobes for unknown reason

Okay, so here is what I'm trying to accomplish: I have four LEDs, under my fish tank, that I want to fade in and out. I want each LED to fade at a different rate, start at a different "brightness" ...
0
votes
1answer
59 views

How to import my own library or file?

I have some small functions to format numbers. I move them to a new file and I would like to import it to my proyect. I can't find how to do it without defining a class (maybe it's the only way). I ...
0
votes
2answers
542 views

Arduino classes, can't get property value

I have tried hard to make a stepper motor work with a class, but I can't get a property returning its value in a method. I get 0 (zero) instead of 26 (expected) from _stepPin. I have tried this->...
1
vote
2answers
46 views

Call class B from Class A

I have two classes in my sketch that are independent of each other (a serial output and an LCD display) A simplified structure of my code is as follows: class A { public: int x; void afoo() ...
1
vote
1answer
43 views

Include Adafruit_RGB LCD Shield library in class

I'm trying to make a class to expand on the functionality of the Adafruit-RGB-LCD-Shield-Library I'm creating this based on what I see from this post. class LcdMenu { #include <Adafruit_MCP23017....
0
votes
1answer
172 views

Errors creating instance MenuBackend and MenuItem attributes in a display class

I am doing a display class using 2*8 lcd on an arduino to display and navigate my menu using MenuBackend library but i can make instance of these variables. I tried using static variable it did not ...
1
vote
1answer
149 views

Should I use OOP?

I am a long time participant in a competition called Robocup Rescue Line. For next year's competition, I am building a robot (and the code for the robot) from the ground up. The tasks that the robot ...
1
vote
2answers
4k views

incompatible types in assignment of 'int*' to 'int [0]'

I was coding a class for "a kind of gun". I have this code for the classes: Gun.h: #ifndef Gun_h #define Gun_h #include "Arduino.h" class Gun { public: Gun(String identifier, String name, int ...
3
votes
1answer
52 views

What is the correct way to create large project files?

I am currently working on a 10x10 RGB LED screen (using Neopixels from Adafruit) and my project files are starting to get rather large. I have several different devices used in this project: The LED ...
4
votes
2answers
8k views

“undefined reference to” - C++

Hi fellow programmers, I started to program Arduino a little deeply and popped out the following error when I was writing a class to read the pulses of a Hall effect flow rate sensor: SensorDeVazao....
1
vote
1answer
15k views

Error: “invalid use of non-static member function” while calling a function from my own class-method

I'm having a bad time trying to call a correctly-working expression (ultra[currentSensor].ping_timer(echoCheck)) from an own class method (myclass::run) instead of from void loop(). I'm getting the ...
1
vote
1answer
229 views

Why does static member std::map reset ESP8266 when outside the .ino file?

Here's an example of a class which crashes the ESP8266-03 causing it to reset: Test.hpp file: #include <map> class Test { public: int data() const; Test(int x); ~Test(); ...
0
votes
2answers
98 views

A class within a class - via an Initialiser Lists: NOT able to update a variable

My test are based on the blog of http://arduinoetcetera.blogspot.be/2011/01/classes-within-classes-initialiser.html. Because I would like to use this idea, I tried with a simple idea, after the ...
1
vote
1answer
21 views

How come `MyClass.MyStaticMethod()` doesn't work, but `Serial.begin()` does?

MyProject.ino: #include "MyClass.h" void setup() { Serial.begin(9600); // MyClass.MyStaticMethod(); MyClass::MyStaticMethod(); } Both uncommented lines work, but the commented (when ...
1
vote
1answer
90 views

Using 2D servo array in my class

I need to use a servo library in my class. I read this question - Use object of other class within class and it works fine for my LCD application, but now I need to use a 2D servo array in my class. I ...
1
vote
3answers
418 views

Run 'Serial.begin(9600)' before loop()

My sketch looks somehow like this: ClassA classA; void setup() { Serial.begin(9600); classA = ClassA(); Serial.println("Bar") ... } void loop() { classA.functionFoo(); } The ...
0
votes
1answer
525 views

Library, instantiation of a class object

I am python experienced, an arduino noob, and absolutely no experience of C other than what has been forced upon me by arduino use. I have just spent a day hammering google for the precise syntax of ...
1
vote
2answers
51 views

Why is my class losing a field in the middle of a method

I have a class with a byte (stripLength) that seems to just disappear in the middle of the frameStep() method. I'm not especially skilled with C++ (or non-VM languages in general), but I believe it's ...
1
vote
1answer
53 views

Object can't get the right value of its property

I'm doing a program for a robot and I got stuck at a weird problem: I have classes defined for my robot's internals, for example for a StepMotor. I also defined a class for a Controller, which is ...
1
vote
1answer
1k views

Avoid global variables with classes

I want to avoid global variables when using my own classes in Arduino. Here is a example. void setup(){ /* setup here */ classA objectA; } void loop(){ objectA.someMethod(); } I know that my ...
0
votes
1answer
1k views

Debugging my created Library - Error - request for member … which is of non-class type

This seems to be a very common error, I am struggling to understand what exactly the solution to this is. I am attaching everything, library files, code, and errors. If you have a moment, I need ...
0
votes
3answers
833 views

Initialize a class (HX711) within a class with constructor and parameters

I am far from being an Arduino specialist, so please bear with me if some of my code below is far from correct. I am writing a sketch in which I need to use 3 instances of the HX711 library, as I am ...
0
votes
1answer
64 views

creating object of another class when initializing an object of a class

Here's what I want to achieve: I'm building a class for controlling step motors. In that class I want to have a method called "init". In that method I'd like to create an object of class Tone, which I'...
2
votes
1answer
1k views

How to call class A's method from class B?

I wish to access methods and fields, as well as change them, of class A from class B. Since the main Arduino sketch is not a class, but a list of fields and methods, I created a separate MainClass ...
0
votes
2answers
1k views

Access method from main sketch inside class

I am lost at this one. In Java, I would do it this way: Inside the main sketch, I would instantiate the object from the class: do = new DoClass(this); I would also include a method inside the main ...
1
vote
1answer
704 views

Inheritance not working as expected

Short version: This is a lighting control project. Some of the clases are Pin and Channel. Channel contains a Pin. Pin is a base class for DigitalOutPin and will be the base class for AnalogOutPin, ...
3
votes
2answers
857 views

How do I use interrupt service routines inside libraries and classes?

I'm trying to have a millis() timer run to emulate a hardware timer inside a library, but I'm having issues compiling the code. I want the callback (pseudo ISR) to be part of the class, and not use ...
0
votes
2answers
2k views

Dynamicly sized array as a class member

I want to create a dynamic sized array of chars as a member in a class. This is being done inside a library that I've created. I have the .h and the .cpp files created. I'm not sure how to declare ...
1
vote
1answer
1k views

Create a library without a class?

I'd like to know if it's possible to create a library for Arduino that does not contain a class, just functions. I know how to create a library with a class, but I'd like to create a library of ...
0
votes
2answers
522 views

Can't play melody and FastLED lights at same time

I'm trying to make an OO state machine based program to play music and lights at the same time. It uses the FastLED library and a 13 pixel neopixel strip. I've confirmed that with the currently wired ...
0
votes
1answer
153 views

Possible Arduino Uno c++ compiler bug?

I recently gave the students in my Arduino-based programming class a project to write some simple unit tests and fix the bugs that they encountered as they did. The class in question mostly stores a ...
3
votes
2answers
6k views

using enums in functions

Given the following enums enum RelayState { RELAY_OFF = HIGH, RELAY_ON = LOW }; enum class CrossingZoneState: uint8_t { CROSSINGZONE_CLEAR = 0, // no train in crossing area, also initialized ...
0
votes
1answer
294 views

Use object of LiquidCrystal class within another class

I am quite new to C++ and hope that I don't bore you too much with my question. I want to use an object of LiquidCrystal Class in another class called "Display_ManagerClass". I followed the ...
1
vote
2answers
12k views

How do I correctly use enum within a class?

I am trying to set the status of an object from a private enum and I'm not sure how to get the private member to the public version in the constructor, and I'm pretty sure I should not be using byte ...
0
votes
1answer
1k views

Using #define and multiple classes

I am using the FastLED library in my program and the basic usage is that the following lines go at the top of the main sketch: #include <FastLED.h> #define NUM_LEDS 60 #define DATA_PIN 6 You ...
0
votes
1answer
306 views

Instantiating bounce library inside a class

I am trying to get my head around how to instantiate objects from existing libaries inside a class object. Specifically I am trying to get the bounce2.h debouncer working. At the moment my code ...
1
vote
1answer
107 views

Defining object

I am trying to hide libraries behind another, for simplicity. But I can't deal with the objects required by the libraries. Basically I want to use the objects both in my .cpp and .ino file, but I am ...