Questions tagged [c++]

C++ is the standard language used to program the Arduino IDE. However, the Arduino IDE does have lots of libraries built in, so functions such as "main" are not called directly in the sketch code. Most Arduino code online is written in this language.

Filter by
Sorted by
Tagged with
0 votes
2 answers
43 views

How to return a value from a non integer input between 0-5 from an output range of 0-320 in map() method

I am experimenting using the map() method in an ArduinoIDE sketch in an attempt to obtain a pixel position for a horizontal meter in the range 0-320 from an input value in the range 0-5. However, ...
  • 49
0 votes
0 answers
17 views

enum class - not declared in this scope (Arduino IDE) [duplicate]

Why does this code: void foo() { } enum class Foo {bar}; bool bar(Foo arg) { return arg == Foo::bar; } void setup() {} void loop() {} throw a compiler error: (3:10: error: 'Foo' was not declared in ...
user avatar
2 votes
1 answer
95 views

Why is sensitivity (threshold) parameter ignored

Analog pontentiometer connected to an Arduino. simplest possible setup. The goal is to send a message over Serial whenever the value changes. I do not want to spam the Serial connection to much, so ...
  • 125
3 votes
2 answers
438 views

Where does this sketch have Undefined Behavior?

Simple sketch and simple question: where does this sketch have undefined behavior? Note: I don't need a solution to fix the code. I already have code that works. I really need to understand where my ...
0 votes
1 answer
48 views

integer overflow in expression of type 'int' results

i need to wake up my ESP every 60 min to read some data and post it to server, all process working fine when i use numbers of minute below 60 (converted in microsecond x 1000000) but when i use 60 min ...
-1 votes
0 answers
60 views

Upload Error on Esp8266

I am trying to upload my code I found online a while back for my MPU6050. It was working great for a long time, but when I went to upload it today it gave me a error message: C:\Users\Liamn\...
-1 votes
0 answers
29 views

Init code of static initalisation vs. setup()

If I define some static objects outside of the setup() or loop() function, when do their initalisation run? Is it ok to use peripherials in this initalisation code? Eg. class SomethingWithSerial { ...
  • 99
-1 votes
1 answer
59 views

6 Pin BME280 Not giving 12C Signal

I'm Creating a telemetry package for my my mom model rocket with a MPU6050, a BME280, and a SD reader/writer. All code I found for the BME does not read any information. When I upload an I2C checker, ...
1 vote
1 answer
53 views

Setting pinmode() in header file

I am trying to have a header file to handle all my pin definitions and pinmodes. This is the header: #ifndef __HEADER_TESTER__ #define __HEADER_TESTER__ #include <SoftwareSerial.h> const byte ...
  • 1,345
-1 votes
1 answer
36 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(...
  • 133
-1 votes
1 answer
77 views

Carbon dioxide sensor MG 811

I am using MG811 carbon dioxide sensor with ESP8266 module. CO2 values is being read inside closed room. The value comes around 400 ppm. Using CO2 generator does not make increase in reading. Checked ...
1 vote
1 answer
47 views

Passing function as argument, with capture, what type to declare in function? [closed]

This probably has a simple resolution, but can't find the right combination. I'm trying to setup a function (setupScreen) to take as an argument a function to do the actual setup: void ScreenHelpers::...
0 votes
2 answers
78 views

How does Arduino handle passing this union?

I'm unsure how this will be handled by the Arduino compiler. If anyone can explain what and why, I'd appreciate it. This is obviously very simplified, but it does contain the actual issue. At the ...
  • 231
1 vote
0 answers
66 views

object of "ESPAsyncWebServer" causing conflict

I have been trying to develop multi cpp project in platformio and whenever I define ESPAsyncWebServer class object with the extern in defines.h and declare it in main.cpp I am getting scarry looking ...
  • 11
3 votes
1 answer
349 views

how to transfer json to string?

I am getting a json object from aws iot MQTT. Assuming that json from aws is {status:opened}. Here is my code. #include <ArduinoJson.h> void messageHandler(char *topic, byte *payload, unsigned ...
  • 53
-2 votes
1 answer
83 views

Arduino code giving error while compiling [closed]

I am a beginner, and I'm trying to make code to control a servo using two ultrasonic sensors. I've tried to make the code, but when I tried to compile it using my simulation app, it gives this error: ...
0 votes
3 answers
105 views

How to abort compilation based on a "wrong" value in a variable

I looking for some code that can generate a compile time error when a variable contains a wrong value. I once started with this code in a c program: #define FIFO_BUFFER_SIZE 8 #define ...
  • 121
-1 votes
2 answers
73 views

A few Bitshifting questions!

So int in Arduino is 2 bytes, which could technically hold up to a value of 65535. However, the MSB is used as a sign bit, so now we have -32,768 to 32,767. So it's a signed integer, easy stuff. While ...
0 votes
0 answers
41 views

ESP32-WROOM-32 Wifisecureclient read() result in gibberish data

We are testing our own library with ESP32-wroom-32. In the .cpp file we have: void HttpDownstreamClient::tokenCreate(char* URL, char* Subname, char* Suber, int expiretime) { Serial.print("The ...
  • 1
-1 votes
1 answer
92 views

How to write arduino code in a c/c++ script

I'm pretty new to arduino. But I have some knowledge about programming in c/c++. I know that arduino is written in c. But it can't be used as normal c/c++ code. for example , instead of including some ...
1 vote
2 answers
142 views

Array of Functions

I'm new to C++. How to make a menu without if() {} else {} & switch() case? I made a menu on an array, but for some reason it doesn't compile. How to correct it? typedef void (*cbd)(uint8_t, ...
  • 27
1 vote
2 answers
374 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 { ...
  • 27
-2 votes
1 answer
123 views

1Hz & 32Hz from 32.768 kHz on ATmega328P at 8MHz & DS3231 32K

I have a 32.768 kHz signal at the ATmega328P input. I need to get 2 signals from this signal: 1Hz and 32Hz. How well will it work? How to do this with a ATmega328P Timer/Counter? What gain will the ...
  • 27
-1 votes
1 answer
45 views

Function call only works if called once

I have 3 LED chains which are all mapped to concentric rings. Each ring has a its own 2D array with the chain number & LED number. I have a function that is passed a ring array and then lights the ...
  • 149
1 vote
0 answers
55 views

Need help with calling an API using an Arduino system

As stated in the title, I need help with calling an API. I'm trying to integrate make a call using the Verkada API but it seems to be using a cURL library that I'm not entirely certain I can get to ...
0 votes
1 answer
216 views

CRC8 code not working properly

I need to send a string followed by its CRC8, 0x31 polynomial (= X^8 + X^5 + X^4 + 1), I've coded this successfully after some troubles, but it doesn't seem to work properly when I check the results. ...
  • 11
2 votes
1 answer
153 views

Can't convert string to UTF-16LE for MD5 calculation on an Arduino

TLDR I need to convert text from a website into UTF-16LE format so that I can get the proper MD5 checksum but can't figure out how to go about doing that. This is all happening on an Arduino to log in ...
  • 123
0 votes
1 answer
55 views

Does avr-libc have any reason to word-align C++ class member variables?

This sounds straightforward enough, but I'm struggling to find a good answer. Suppose I declare a C++ class with private members that collectively occupy an odd number of bytes. Say... class Foo { ...
  • 355
1 vote
1 answer
157 views

IF statement inside of a function call? Code help

I was browsing a library for steppers motors when I ran across this line of foreign-looking code: digitalWrite(enable_pin, (enable_active_state == HIGH) ? LOW : HIGH); Is this some kind of shortcut ...
1 vote
1 answer
87 views

AfMotor Shield Library does not work with template programming

I am able to move motors using AfMotor Shield Library. ( https://github.com/adafruit/Adafruit-Motor-Shield-library ) Like : AF_DCMotor insertionMotor(1); AF_DCMotor pumpMotor(2); void setup() { ...
-1 votes
1 answer
87 views

Non-blocking sketch

So far, a part of this code works fine, but Relay 1 keeps turning on and off instead of staying off. My purpose is to turn Relay 7 on, wait 3s, turn Relay 8 on, wait 10s, turn Relay 6 on, wait 10s, ...
  • 11
1 vote
2 answers
104 views

Novice learning Serial.readString()

New to Arduino, getting into String variables and reading them from serial monitor. Basically what I'm trying to do is have the user input either red, green, yellow. Whichever String they enter the ...
  • 11
0 votes
1 answer
81 views

Create member object using constructor arguments, or pass reference to object via constructor

I'm not entirely sure about the proper C++ terminology, so I'll just illustrate what I'm trying to achieve by giving a Java example since it should be pretty obvious: public class LcdDecorator { ...
  • 355
2 votes
1 answer
146 views

Where should unit tests go in the Arduino IDE

I have an Arduino project where the file structure looks like this myProject/ myProject.ino ImportantClass1.hpp ImportantClass1.cpp ImportantClass2.hpp ImportantClass2.cpp ...
0 votes
2 answers
207 views

How to do 'for' loop over inline anonymous array

I have a bunch of pins given names in the header: #define DIP5 53 #define DIP4 52 #define DIP3 51 #define DIP2 50 #define DIP1 49 #define DIP0 48 If it's not obvious, I have a bunch of DIP switches ...
  • 355
1 vote
1 answer
232 views

How to convert a reading to percentage in Arduino [closed]

I am using this example on how to use a photoresistor to detect the value of light that the sensor is getting but I want to convert the reading of the resistor to a percentage but I can't use the map()...
2 votes
0 answers
193 views

Same code working on Arduino IDE but not in PlatformIO IDE

I'm running into this weird problem. My code is working just fine when I upload it to an ESP32 from Arduino IDE. That same code is not working when I upload it using PlatformIO IDE. The same libraries ...
-1 votes
1 answer
54 views

How to shift binary into a shift register (serial in, parallel out) sequentially

I'm trying to make a continuity tester at work where I connect the input and output of a harness into a test fixture powered by an Arduino. This tester tests whether the position of the connects are ...
2 votes
1 answer
325 views

What is wrong with the way I write and or read the EEPROM adresses?

Consider: #include <EEPROM.h> byte guifactor1 = 1; byte guifactor2 = 2; byte guifactor3 = 3; byte guifactor4 = 4; byte guifactorgas = 5; byte guifactorwater = 6; volatile unsigned long ...
  • 35
0 votes
1 answer
68 views

Using a 5 pin button with Arduino Correctly

I am trying to build a simple motor test sketch, currently, to test a NEMA 23 stepper motor and the DM542T stepper driver. Here is the code, and I am having trouble figuring out how to properly wire ...
  • 360
-1 votes
1 answer
68 views

Getting more Hz while working with 3 serial ports (IMU sensors)

im doing a university project where we use 2 IMU sensors and a SD card reader to save the data from sensors. As you will probably see from the code, we specify the sensor port we listen to, save data ...
0 votes
1 answer
59 views

Having trouble reading multiple thermistors w/ Arduino 2560

I'm trying to get my code to read multiple thermistors and I can't quite seem to get it correct using my arduino 2560. The first issue is it's not reading more than the first thermistor. The next ...
0 votes
1 answer
717 views

Integer division

I want to divide two integers and get how often one of them fits into the other completely, so there will always be an integer as an output. In python you do this kind of operation with //.
0 votes
0 answers
579 views

ESP8266 - What is the difference between PSTR() and PROGMEM specifier?

While saving ESP8266 RAM spaces I am confused by the usage of PSTR(), PROGMEM, and lots of _P functions. What I know now is PROGMEM only applies to global or static strings, while PSTR() can only be ...
  • 1
1 vote
1 answer
489 views

How to pass non-static class member to callback on avr platforms?

I am using the PubSubClient library in my own Arduino library. I'm having trouble with trying to assign a class member as the client library setCallback callback function. MyClass.cpp: #include <...
2 votes
3 answers
333 views

why is my char array empty

following sketch will run totally fine and as expected : #include <Wire.h> #include "SparkFun_External_EEPROM.h" ExternalEEPROM ExtEEPROM; char username[33] = ""; char ...
  • 147
2 votes
2 answers
159 views

How to install the application + its configuration to many devices of the same kind? (ESP32)

Being the newbie in the Arduino area... Having more devices, how can I upload some configuration parameters after the code was uploaded? Is it possible? Situation: I have the simple application for ...
  • 147
7 votes
4 answers
1k views

Optimizing code for ATtiny10

I'm trying to squeeze code onto an ATtiny10, but I'm just not getting there. I'm using 1060 bytes and only have space for 1024 bytes. The code is simple enough; I need to read a button pin. If high it ...
0 votes
1 answer
916 views

7-Segment Display w/ Potentiometer

(Backstory) So, I took an computer engineering class in high school (grade 11 level), where I learned a bit about breadboarding as well as arduinos (I would like to stress a bit). It has been 5 years, ...
  • 3
1 vote
2 answers
612 views

uint8_t issues when linking libraries outside of INO file

I've been trying to start my project out split into multiple files, knowing it will grow. I was templating it off of how I've done C++ files in the past: classes in an individual .h/.cpp pair and ...

1
2 3 4 5
21