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
2 votes
1 answer
93 views

How to pass Encoder object to constructor of a different class

I am trying to create a class (Arm) that controls an arm. The arms have 2 motors, each with an encoder, so I pass 4 integers for the pins and I am trying to pass 2 pointers (one for each encoder ...
1 vote
1 answer
2k views

Invalid use of non-static member function

In order to explain my problem I used 3 classes: Actions, Triggers, and Combine. Actions simulates an action function, that is defined externally. Triggers has that function that needed to be executed....
1 vote
0 answers
185 views

Using library functions in timer ISR ESP32

I'm trying to use a library function in my ISR function that uses the internal timer to trigger every 1 ms. The chip that I'm using is an ESP32-C3-MINI. Here is my current code: main.cpp #include <...
1 vote
1 answer
67 views

Cannot instantiate a parameterized object inside of another class

I'm having troubles understanding the inner workings of classes and such. I have a class called Attributes that contains parameters. In my .ino, I can simply instantiate an object with Attributes ...
1 vote
4 answers
994 views

Instances of a class inside another class - is there a way to control the amount?

I have a class with 12 instances of a button, to create a keypad( meaning that this is the only case I use 12 instances). But this class can be just a button array of any other number between 1-12. I'...
-1 votes
1 answer
213 views

How to pass Strem object to my class

I'm trying to creaper class wraper to use an Streamobject but I've an error when I try to compile. My .hfile : #include <Arduino.h> class TestSerialListener { public: TestSerialListener(...
1 vote
1 answer
76 views

How do I properly use an ISR inside a class definition?

I want to write a class for a model bike. For controlling the steering I use a DC motor with two encoders. To get the steering angle stAng of the bike, I attach a interrupt to the pin ST_ENC_A where ...
-1 votes
2 answers
853 views

How to properly put a u8g2 handle in a class

I'm trying to create a small battery powered alarm clock using an Arduino MKRZero and a generic SH1106-controlled, 128x64 pixel oled. I started out just dumping all code into a single file named Clock....
3 votes
2 answers
2k views

Attach the Arduino ISR function to the class member

I intended to use a timer interrupt for limited instances of a class in my ESP32 Arduino project. My first code conception was as follows: portEXIT_CRITICAL_ISR(&lock0); } ...
1 vote
2 answers
1k views

Call functions of one class from another class - Callback

I am new to C++ & I need to call functions of one class from another class. And so that the classes do not know anything about each other. How to do it in Arduino environment? class Encoder { ...
2 votes
1 answer
2k 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
1 answer
100 views

How does a callback function get revoke itself eg. Connect function get revoked when there is new connection

Further to my previous question here Can anyone help me understand how the callback function gets revoked itself? The connect function, disconnect function. BLE custom UUID code source here Another ...
0 votes
1 answer
83 views

Failure using references variables in classes [closed]

Theoretical Q I'm having some trouble when using a referenced variable in a class. Class A have an int a=0. Class B has an instance of Class A, and referencing int &a=A.a, and in the same manner ...
1 vote
1 answer
461 views

Use and definition of a destructor class

I created a class for TFT buttons and messages when using a Wemos 2.4 tft touch display. In a code I use about 12 buttons (3 different screens with 4 buttons in each screen ), for example in my home ...
1 vote
2 answers
9k 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 ...
0 votes
2 answers
1k views

Passing a two dimensional array to a function

I'm working on an led matrix project where I'm running a series of patterns made of bitmap frames. Here's an example: https://vimeo.com/564184465 Right now I'm using a series of method calls named per ...
1 vote
1 answer
79 views

Calling functions between 2 classes

Class myIOT2 contains a function that need to be called from class IPmonitoring: bool myIOT2::checkInternet(char *externalSite, byte pings) { return Ping.ping(externalSite, pings); } This ...
1 vote
1 answer
125 views

2 instanced of ESP8266Ping

I'm using ESP8266Ping lib inside my iot lib which hanldes Wifi connectivity and MQTT messages. Since it create its own instance called Ping when calling #include <ESP8266Ping.h>- it had to be ...
1 vote
1 answer
209 views

Calling class member from .h file

In .ino file I have a class defined (called IPmonitoring).Also, inside the same .ino file, I call a .h file ( which is located "above" class IPmonotoring). When I try to call members of ...
0 votes
2 answers
46k 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 ...
0 votes
1 answer
736 views

Passing a method pointer

I created a small library, which takes a callback function: MyClass::add_callback(bool (*callback_function)(), byte behaviour) { // ... bool result = callback_function(); // ... } So far, I'm ...
1 vote
1 answer
176 views

Doing several things at the same time with functions, objects or interrupts?

First of all, thank you for taking the time to read this. I am a newbie, so apologies (done examples on arduino website, basic C++). I'm trying to get an idea of what the best way to structure a ...
0 votes
1 answer
1k views

Is this class declaration wrong? " Declaration has no storage class or type specifier" error

While trying to setup an ESP32 as mqtt publisher I am getting strange errors. Here is my code: #include "mqttSetup.h" #include <WiFi.h> #include <PubSubClient.h> static byte ...
1 vote
2 answers
218 views

Public variable in class not incrementing

I'm not sure what is wrong with my code, but whenever I call addNewLine, the linesInserted variable is not updating correctly. When I print the value of linesInserted inside of the addNewLine method, ...
0 votes
2 answers
133 views

Is there a limitation of how many instances of the `String` class?

Platform Attiny85 with AttinyCores 1306 OLED i2c with Tiny4KDisplay Goal using a joystick for menu navigation up/down choose left enter (not finished yet) right back (not finished yet) inverse ...
0 votes
1 answer
358 views

How to declare a pointer for arduino neopixels library so I can set it up in the setup function with dynamic variables?

I am using NeoPixel strips, and I want to be able to declare a pointer to them, but not initialize them until the setup function (because they will initialize with certain variables only made ...
1 vote
1 answer
156 views

Object composition (class uses class)

I would like to write a class which utilises another class and it´s member functions. I found out that this is object composition and read some examples of how to do it but it ither doesn´t work for ...
0 votes
1 answer
293 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 ...
1 vote
0 answers
195 views

Problem with a class? SHT21 library

I am using ESP32 and SHT21 temp+humidity sensor but while compiling the code I get the following error: variable "SHT21" is not a type name I see an SHT21 class defined in the SHT21.cpp ...
0 votes
0 answers
2k views

ESP8266 - Problem with LittleFS after reboot (solved in comments)

I'm trying to create an even log saved on flash. I try to make it a class, called flashLOG as shown. Code behaves as expceted, reads, writes and posts it size and entries. The problem is that after ...
0 votes
1 answer
270 views

Using a template inside a class

I'm trying to use a template function, but I get an error home/guy/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-...
2 votes
1 answer
637 views

Use ISRs inside a library more elegantly

At the moment I try to make a library which uses attachInterrupt(?,?,RISING) to read a sensor. The article of Nick Gammon on Calling an ISR from a class helped me a lot, but his "Glue routines" get ...
0 votes
1 answer
408 views

EspMQTTClient inside a class

I'm trying to use EspMQTTClient inside a class, called myIOT32. An error, which I don't find the reason for is generated. /home/guy/Documents/git/Arduino/libraries/myIOTesp32/myIOTesp32.cpp: In ...
22 votes
5 answers
79k views

What overheads and other considerations are there when using a struct vs a class?

C on embedded systems has traditionally use structs to hold structured data. Arduino brings C++ to the table, so we can use classes instead. Lets say we have two different data structures which ...
0 votes
1 answer
3k views

Interrupts inside a class attaching to the function of the class

Hello i have a class and i would like to attach an interrupt inside the class and attach it to a function of the class. class counter{ public: counter(int pin){ Ipin=pin; } void ...
1 vote
0 answers
124 views

Get value from protected member of class

i'm really new to Arduino. I have Arduino Mega, a USB host shield and a barcode scanner. I'm using this library >> link and modified it example so barcode scanner worked (Got it from here) to read ...
1 vote
1 answer
2k 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, ...
0 votes
1 answer
4k views

How to loop over objects or pass object to function?

I'm not sure if this is more of an C++ question, but I've looked up both and still have no idea. I have a sketch which controls 6 stepper motors using the AccelStepper library and in order to ...
0 votes
1 answer
302 views

Protecting variables and functions within a library that has no class

If you want to have functions within a library that only the library itself should be able to use or variables that shouldn't be accessed from outside, you usually make them private by writing this in ...
0 votes
1 answer
279 views

Using a class inside of another class [closed]

I have a seemingly simple problem that seems to be popular, but after searching several forums I still have not found the answer: How do you use a class inside of another class? I have simplified my ...
1 vote
4 answers
989 views

How do arrays work?

It's been days now I'm trying to figure out how arrays work in Arduino IDE. For better understanding, I assembled some pieces of code I found here and there to write this sketch: #define arrayLength(...
1 vote
1 answer
2k 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
2 answers
2k 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
2 answers
2k 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->...
0 votes
1 answer
61 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 ...
0 votes
1 answer
102 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::...
0 votes
2 answers
73 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 ...
1 vote
1 answer
69 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 ...
0 votes
1 answer
2k 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
0 answers
233 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"; } ...