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
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 <...
Max's user avatar
  • 111
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 ...
EricWeissman's user avatar
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 ...
AJ_Smoothie's user avatar
-1 votes
1 answer
211 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(...
simon's user avatar
  • 133
1 vote
1 answer
75 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 ...
Ole's user avatar
  • 13
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 { ...
Andre's user avatar
  • 27
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 ...
Just doin Gods work's user avatar
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....
guyd's user avatar
  • 1,033
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); } ...
Hamid s k's user avatar
  • 143
1 vote
4 answers
989 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'...
guyd's user avatar
  • 1,033
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 ...
guyd's user avatar
  • 1,033
1 vote
1 answer
460 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 ...
guyd's user avatar
  • 1,033
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 ...
Chris Schmitz's user avatar
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 ...
guyd's user avatar
  • 1,033
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 ...
guyd's user avatar
  • 1,033
1 vote
1 answer
206 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 ...
guyd's user avatar
  • 1,033
0 votes
1 answer
730 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 ...
MacFreek's user avatar
  • 103
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 ...
Zhelyazko Grudov's user avatar
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 ...
Zaffresky's user avatar
  • 183
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, ...
DuluthIsSuperior's user avatar
0 votes
2 answers
132 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 ...
River's user avatar
  • 103
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 ...
Erik Weisbrod's user avatar
1 vote
0 answers
194 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 ...
Zaffresky's user avatar
  • 183
-1 votes
2 answers
852 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....
Simon's user avatar
  • 107
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 ...
guyd's user avatar
  • 1,033
0 votes
1 answer
268 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-...
guyd's user avatar
  • 1,033
2 votes
1 answer
635 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 ...
Adrian Immer's user avatar
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 ...
guyd's user avatar
  • 1,033
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 ...
Jack's user avatar
  • 213
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 ...
mheavers's user avatar
  • 237
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 ...
Pnzy's user avatar
  • 11
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 ...
LukasFun's user avatar
  • 295
0 votes
1 answer
277 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 ...
Titan's user avatar
  • 3
1 vote
4 answers
987 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(...
MrCabana's user avatar
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'...
user avatar
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 ...
Chris Schmitz's user avatar
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::...
Michel Keijzers's user avatar
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 ...
Jim Mack's user avatar
  • 235
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 ...
guyd's user avatar
  • 1,033
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 ...
Craig's user avatar
  • 113
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 '...
Brethlosze's user avatar
2 votes
0 answers
230 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"; } ...
Kostas C.'s user avatar
2 votes
0 answers
515 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. ...
Tarlyo's user avatar
  • 21
0 votes
1 answer
142 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 ...
guyd's user avatar
  • 1,033
1 vote
1 answer
69 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; ...
saleh a.a.a's user avatar
0 votes
1 answer
74 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 ...
rcpilotp51's user avatar
1 vote
3 answers
1k 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 ...
R1S8K's user avatar
  • 283
1 vote
1 answer
2k 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 ...
Emil Jacobsen's user avatar
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(),...
Brethlosze's user avatar
2 votes
1 answer
3k 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 ...
user3552818's user avatar