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.

Filter by
Sorted by
Tagged with
0
votes
2answers
68 views

Callback functions when using a class

This question is somewhat similar to How to pass non-static class member to callback?, but there are a few differences, especially since a lot of my uses have "interesting" additional complexities. I'...
0
votes
1answer
33 views

Having an issue accessing values from a pointer

Context This may be more of a C++ question than an arduino specific question, but it's dealing with arduino c++ so I thought I'd start here. I'm building a class to abstract some simple melody ...
1
vote
1answer
53 views

Segmentation fault and huge SRAM need for Serial.println

I have written my own 'assert' since I want to use it for both Windows and Arduino. The class is called from many files (about 10). AssertUtils.h: #pragma once #define assert(expr) AssertUtils::...
1
vote
2answers
45 views

Is code in a class repeated for each instance? [closed]

I haven't needed classes before in programming for Arduino, but I now have a good use case. I'm not sure I grasp how this will affect code space, though. Currently I have a struct that holds the ...
0
votes
1answer
76 views

AttachInterrupt - fail to initiate inside a class [duplicate]

I'm trying to create a class that uses attachInterrupt, but get this error msg: In member function 'void ledDoor::attach()': ClosetLedStrip:31:82: error: invalid use of non-static member function ...
0
votes
1answer
46 views

Class help - Same Object types seem to mix values with each other

I'm having issues with two objects of the same class type. I have a LED class, which has functions to fade in and out, a LED. In my code, I create two objects of this class, and on the board, I fade ...
1
vote
1answer
128 views

Create New Serial Class Inheriting from Stream

How should I inherit from Stream, for creating a new class MySerial able to be initialized from a Stream0 instance?. The error so far is: "cannot declare variable 'mySerial' to be of abstract type '...
1
vote
0answers
64 views

Using pointer to a Global function

I am trying to store and use a pointer to a global function. The function global_f returns a String and takes an object as parameter: String global_f(Request r){ // ... return "This is it"; } ...
1
vote
0answers
94 views

Millis() is Not Working

I have a sketch that uses two timers using millis() from a library I created to keep time. The timers seem to be working correctly, but when I print the start time of each timer, it is clearly wrong. ...
0
votes
1answer
48 views

give a class's function name as a parameter [closed]

I'm trying code using FastLed library to have a 3 state ( color or brightness ) led strip, using a physical input switch, while each press will change leds color, using a predefined list. code below ...
1
vote
1answer
54 views

Trying to understand Classes

I have searched about class and int but I still don't understand. I have seen this code online I want to understand it class Motor { int enablePin; int directionPin1; int directionPin2; ...
0
votes
1answer
45 views

Trying to Pulse an LED a number of times outside of the main loop

I'm trying to call a class function that pulses an LED "x" number of times. I dont want to use a delay, which is making it tough. If I use a while loop, the LED just stays on. I attach an interrupt in ...
1
vote
3answers
546 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
226 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
480 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
1k 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
143 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
481 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 ...
1
vote
1answer
134 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
166 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 ...
1
vote
1answer
181 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
664 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
797 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
670 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
103 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
87 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
780 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
48 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
46 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
196 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
200 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
6k 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 ...
2
votes
1answer
61 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 ...
3
votes
2answers
15k 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
21k 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
342 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
105 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
22 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
137 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
479 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
803 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
52 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
60 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
2k 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
4k 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
1k 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
92 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
2k 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
2k 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
886 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, ...