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.

learn more… | top users | synonyms

0
votes
1answer
46 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
69 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
13 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
58 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
37 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
49 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
34 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 ...
0
votes
1answer
68 views

Pass class's public function as an argument to external command

I am trying to write a library for encoders. main.ino: #include <./Encoders.h> Encoders encoders(); void setup(){ Serial.begin(9600); } void loop(){ Serial.print(""); ...
2
votes
1answer
26 views

Mysterious behavior when using objects

I am writing a project that involves using complementary filters to combine gyroscope and accelerator readings in 3 directions. The relevant code is below. class CompFilter { public: long ...
1
vote
2answers
196 views

Arduino declaring class in h and cpp file Undefined Reference

I am trying to compile my project, but unfortunately get errors. I created class and separated implementation and declaration (cpp file and h file) Here they are sensor.h #ifndef SENSOR_H ...
1
vote
1answer
228 views

pass class internal function as callback

I am trying to pass a class internal function as a callback function within the class. The error behavior is similar to this problem. Whatsoever, I was unable to construct working code based on that ...
3
votes
1answer
37 views

Class is not tracking changes to a private field

I have a program where a device registers itself with a command object. The command object is losing track of the registrations. The following program repeats "0 devices registered" even though when ...
0
votes
1answer
38 views

serialEvents within a class

My .ino looks roughly like this #include "command.h" Command command; void setup() { } void loop() { } command.h class Command { public: Command(); }; command.cpp #include ...
0
votes
2answers
78 views

C++ Namespace/scope problem when trying to attach arduino interrupt

I have defined a c++ class (RpmDriver) and want to use attachInterrupt in the constructor to link an Arduino pin to its ISR (RpmInt) in the class. When I try this, I get: error: cannot convert ...
0
votes
1answer
30 views

Problem assign float to an embed class within the Linked-list libary

I have successfully implemented some code which uses a linked-list. Everything is working, except assigning a value to a float within the embeded class. When I run the code below, I get the expected ...
0
votes
1answer
72 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
1answer
118 views

Inheritance: error in calling the constructor of the base class?

I want to write a library for the RGBDigit shield (http://rgbdigit.com/), which essentially is an Adafruit Neopixel strip, packed as a 7 segment display. The shield also has a DS3231 clock and an IR ...
0
votes
2answers
320 views

Pass a member function pointer to a method of a foreign class (EDB Lib)

I'm currently working on my own arduino library and I'm becoming exasperated with the following problem: I want to store data with the extended database library ...
10
votes
3answers
875 views

Classes and objects: how many and which file types do I actually need to use them?

I have no previous experience with C++ or C, but know how to program C# and am learning Arduino. I just want to organize my sketches and am quite comfortable with the Arduino language even with its ...
0
votes
1answer
264 views

Can't use base class and derived class functions

I have made two libraries and one test program.I have made my custom uart library.first i have included all functions for printing in single uart library file.but then i have made print library for ...
2
votes
1answer
530 views

Custom Arduino library problem

I have made my custom serial(UART) library. So I made uart.h and uart.cpp files as following. uart.h #ifndef UART_H #define UART_H #include <avr/io.h> #include <stdlib.h> ...
0
votes
1answer
317 views

Call a class method from inside the same class

If i have file cSpeedOfSound.h: #ifndef cSpeedOfSound_h #define cSpeedOfSound_h #include "Arduino.h" #include "math.h" class cSpeedOfSound{ public: cSpeedOfSound(float *i,float *C); ...
0
votes
2answers
2k views

Arduino raise the error: `does not name a type` when an Object is used outside of the main two blocks setup and loop

I have this: class Person{ public: int age; }; Person p; p.age; void setup() { ... } void loop() { ... } And I got this error: Compiling 'MyProgram' for 'Arduino Mega w/ ATmega2560 (Mega ...
0
votes
1answer
124 views

How to dynamically switch between between 2 objects?

I have a 40x4 LCD which internally consists of 2 40x2 LCDs. To control this LCD I have to create 2 LiquidCrystal objects and than later on in code decide which one to use depending on which of the 4 ...
1
vote
1answer
1k views

Use object of other class within class

I am writing a class for a project which will take care of handling any LCD updates for my project. The way I want to handle this is to initialize the LCD object in my main file, and then pass the LCD ...
0
votes
1answer
368 views

Variables not initialized in Class Constructor

I'm creating a library driver for AdaFruit's GFX library. During Constructor initialization, all the variables (set in another .cpp) are returned as zero. This code has several modular files to ...
1
vote
1answer
389 views

error: 'CLASS' does not name a type only when creating object inside another object

I'm trying to use Adafruit's LED Backpack library within a custom class. When I use the Adafruit library directly within a sketch, it compiles fine. When I use an example sketch provided with the ...
1
vote
2answers
145 views

How to prepare data structures and classes?

How can I port these structures to arduino ide, I also get error when I define pointers // pointer to classes example #include <iostream> using namespace std; class Rectangle { int width, ...
0
votes
1answer
561 views

Calling a function that is outside of a class from inside

I have an Arduino sketch with a timer interrupt class and would like to place the TIMER2Services() function in the TimerTwoTest.ino file for easy access. On compile I get a multiple definition of tmb2 ...
5
votes
1answer
426 views

Arduino Servo won't move when using classes

I'm trying to make a class work with Arduino, however it doesn't seem to trigger properly. The code is compiling perfectly, and it's supposed to control the leg of an hexapod. Also, the example sweep ...
1
vote
1answer
171 views

Initialize a “Matrix” object in my own library?

So, I'm trying to make a custom library to drive a 8x8 Bi-Color LED Matrix from 2 MAX7219's that incorporates two "Matrix" objects from the "Matrix" library and I cannot, for the life of me, figure ...
4
votes
5answers
989 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 ...