Stack Exchange Network

Stack Exchange network consists of 175 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.

0
votes
1answer
28 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
51 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
47 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
31 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
50 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
39 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
464 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
67 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
220 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
760 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
111 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
335 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
111 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
84 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
35 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
113 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
494 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
448 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
514 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
96 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
70 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
606 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
47 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
182 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
169 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
5k 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
55 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
10k 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
17k 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
267 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
102 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
102 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
449 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
617 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
57 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
2k 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
925 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
75 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
776 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
965 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
3k 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
557 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
178 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 ...