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.
-1
votes
0answers
42 views
how do program the interrupt routine?
I am having some trouble programming my interrupt routine using this library that interfaces with the timer1 on my arduino uno.
I am having issues with calling a non-static member within a static ...
1
vote
1answer
26 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
33 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
11 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
34 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
10 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'...
1
vote
1answer
73 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
54 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
70 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
1answer
76 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 to have the callback (pseudo ISR) be part of the class, and not ...
0
votes
2answers
78 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
73 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
63 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
57 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
175 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
23 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
151 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
104 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
67 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
50 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
141 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
30 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
704 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
571 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
39 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
2answers
113 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
106 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
35 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
139 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
149 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
463 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 (https://code.google.com/p/arduino-edb/)...
12
votes
3answers
1k 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
378 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
640 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>
//creating ...
0
votes
1answer
534 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
3k 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
188 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
3k 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
502 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
442 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
154 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
738 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
475 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
184 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
1k 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 ...