All Questions
Tagged with class programming
15 questions
0
votes
0
answers
122
views
Initializing both I2C devices of a RP2040 Rpi Pico with Earle Philhower Core
I'm using the Arduino IDE (v1.8.19) with the Earle Philhower core to program a Raspberry Pi Pico (RP2040) board.
I2C bus 0 of the Pico (pins 4 (SDA) and 5 (SCL) are coupled to a first MCP23017 port ...
-1
votes
2
answers
1k
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....
0
votes
1
answer
4k
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 ...
0
votes
1
answer
143
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::...
1
vote
1
answer
977
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 ...
1
vote
2
answers
76
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
1
answer
56
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
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
336
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 ...
4
votes
2
answers
24k
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 ...
2
votes
1
answer
8k
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 ...
21
votes
3
answers
9k
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 ...
1
vote
1
answer
9k
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);
...
1
vote
1
answer
18k
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 ...
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 ...