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
0answers
10 views

Please , explain about MAX30100 using for Arduino to read ADC in format (0-1023)

can anyone help me..? I am using MAX30100 with arduino, and my expectation is i can to process the ADC as usual (0-1023), but I do not understand the signal processing. Has anyone used the MAX30100 ...
0
votes
0answers
17 views

Ultrasonic sensors not working

The target of this is for the system to print "Done" when distance, measured by 2 ultrasonic sensor, is between 6-17 cm. This is my python code: import serial arduinoSerialData = serial....
-1
votes
0answers
29 views

expected unqualified-id before numeric constant [closed]

hellow. class Easy_Drv8833 { private: int Motor_A_1; int Motor_A_2; int Motor_B_1; int Motor_B_2; enter void pinSetup(){ pinMode(Motor_A_1, OUTPUT); /...
0
votes
1answer
37 views

ARDUINO expected ';' before 'delay' [duplicate]

I want to shine LED in 64 of 255 duty cycles = level of brightness but it pops up this error (see picture). Can anybody tell me why and help me ? Thank you. void setup() { // put your setup code ...
0
votes
1answer
47 views

Code for 2 ultrasonic sensors

This is my code: int trigPin=13; //Sensor Trig pin connected to Arduino pin 13 int echoPin=11; //Sensor Echo pin connected to Arduino pin 11 float pingTime; //time for ping to travel from sensor to ...
0
votes
0answers
25 views

Integrating blinking light code and time on/off code

I'm trying to integrate code from one of my projects with another. One is code that blinks some Adafruit Neopixel LED strips at a specific rate and the other is a time on/off circuit here is the code ...
0
votes
2answers
51 views

Function declared in another file not recognized (undefined reference to)

I am making a multi-file arduino project, but the compiler can't recognize a function. I am using the arduino-cli version 0.10.0 This is the error I received undefined reference to pin_init() collect2....
0
votes
1answer
13 views

Weird RTC DS3231 Output only when saving the dates to variables

I am sorry to ask this question as I think it has more to do with my mediocre C++ programming skill than with the arduino. I do have a project where I want to use an RTC DS2131. I started out by using ...
0
votes
1answer
27 views

Use callbacks in Arduino with pointers to functions (will functions persist in memory?)

As I been learning Arduino (micro controllers, c++, etc) I have learned that memory is very limited. I already understand how memory works when it comes to variables. But I do not understand how ...
-2
votes
2answers
53 views

Question About The Error In This Code

Could someone point out what exactly I'm screwing up here and provide a specific solution. Here's the error message: Arduino: 1.8.13 (Windows 10), Board: "Arduino Uno" sketch_jul24g:38:11: ...
10
votes
5answers
3k views

Why is it considered bad practice to use the 'new' keyword in Arduino?

I previously asked this question: Is it required to delete variables before going to sleep? On that question, @Delta_G posted this comment: ... Really on a microcontroller I would create the object ...
0
votes
2answers
43 views

Serial port usage in code

I want to write a function that defines a serial port based on a flag but I'm not sure it's possible. For example: void writeToSerial(bool useSerial1) { SerialPortClass serialPortObject; // Is ...
1
vote
1answer
111 views

Is it required to delete variables before going to sleep?

This tutorial shows how to put the arduino to sleep and use a watchdog to wake up at intervals: https://youtu.be/urLSDi7SD8M I been studding c++ and as I am getting better I am instantiating objects ...
1
vote
2answers
209 views

What exactly does the return type do in a function?

something I've never understood and still don't is, what does the return type do specifically? Everyone in tutorials just say that void returns nothing and int returns int, etc. But what does that ...
0
votes
0answers
46 views

How I can send data information without work WiFi to LCD?

Hi everyone I am beginning learn coding and the second language English. I have small project I use Arduino uno , esp8266 , dht11 , lcd I2C and use blynk app in my project I have the code and work ...
0
votes
1answer
35 views

How can I assign the value of a char array to a uint8_t array?

I have a char array variable that has a value. I need to send this value through LoRa. The library I use for the LoRa implementation accepts an array of uint8_t. How can I pass the value of a char[] ...
-2
votes
1answer
40 views

Any limitation on array size in Arduino Mega 2560?

I am writing an Arduino code with 3 arrays. Two of those are double and other one is int. Further first two arrays have nearly 420 elements for each. Now I noticed that with more that 89 elements on ...
0
votes
2answers
42 views

How to convert RGB values to Intensity

I made an arduino color sensor with tcs3200 and arduino uno. I have coded the arduino to find the RGB values when I place the color paper below the sensor. How can I derive the intensity using the RGB ...
2
votes
1answer
39 views

if I add a .cpp file, Serial becomes unusable

I am using the mega 2560. When I just use .ino and .h files, if I use Serial, it works fine, without even using: #include <SoftwareSerial.h> However, when I add a .cpp file I start getting 2 ...
0
votes
1answer
36 views

Getting enum name from enum instance [closed]

Hello Arduino Stack Exchange, I have an an enum instance called state: enum States { SLEEP, AWAKE, CRAZY } state; States state = SLEEP; I would like to convert the value of state to a String so ...
0
votes
2answers
36 views

Am not able to call C++ function pointers from inline assembly

Due to some curiosity, I was trying to use some assembly with my Arduino MEGA 2560. I am not able to invoke a function from a c++ function pointer array. When I uncomment the call function, func_a ...
1
vote
1answer
155 views

Int64_t aka long long acts as int32_t and overflows at 2^31

I have an int64_t variable. When I add another int64_t variable and convert it to a double to print it on the serial monitor, it acts as if it was a int32_t variable. This is the program: int64_t a =...
0
votes
1answer
39 views

Assigning an empty array row to reference [duplicate]

int colors[][3] = { { 255, 0, 0 }, { 0, 255, 0 }, { 0, 0, 255 }, { 253, 7, 210 } }; int (*EXCLUSIVE_COLOR)[3]; I have a two-dimensional array to store some color values. I have a 2nd ...
0
votes
1answer
24 views

Compile-time 'Undefined reference' error for functions defined in a .cpp source file that are called in my main project file

I'm currently working with the NodeMCU ESP12E and MPU6050 IMU using the Arduino IDE and wanted to create a project that has a .h file that declares the variables and functions. In the .cpp file, I ...
0
votes
1answer
38 views

Matrix and State Space Arduino Implementation

I wrote an Arduino Matrix class. Then I used this class to implement State Space on Arduino. During tests I stomped upon a problem. After starting the program it stops at some point. I have no idea ...
2
votes
1answer
109 views

Use ISRs inside a library more elegantly

At the moment I try to make a library which uses attachInterrupt(?,?,RISING) to read a sensor. The article of Nick Gammon on Calling an ISR from a class helped me a lot, but his "Glue routines" get ...
0
votes
0answers
23 views

conver UUID to string for mqtt publish

I am trying to publish jason to mqtt. Following is just a snippet of a code.When i try to add data["uuid"] to json data doesn't get published to MQTT, if I omit data["uuid"] everything works. UUID is ...
0
votes
1answer
30 views

Is it possible to count rising edges of a 4 MHz clock on an Arduino Due and trigger an interrupt like all 4'000'000 edges?

I am struggling with my Arduino Due and the Timer Counter functionallity. The following is what I am trying to achieve: I want to execute a function to a specific point of time or more precisley ...
0
votes
0answers
40 views

ESP32 Low Power Reconnect Latency Question

I am trying to develop a small 9-button BLE keyboard on the ESP32 with a rotary encoder as a volume knob. My question involves the low power modes and the time it takes for them to wake up. My ...
0
votes
1answer
20 views

strcat gives error when I try to add a char to a char array

I have char c; where int bt_available = Serial2.available(); if (bt_available) { c = Serial2.read(); } and later in the code I try to strcat(some_char_array, c); and it gives me this error ...
0
votes
1answer
24 views

Pushbutton and switch case follow up question

PROBLEM STATEMENT: A circuit is measuring various parameters (Temperature, Humidity, etc.) through sensors connected to it continuously. When a Push Button is Pressed and Hold for 2 seconds in ...
0
votes
1answer
109 views

Pushbutton and switch case

I am developing a project for my college. PROJECT OUTLINE: There are 3 sensors (Temp., Accelerometer & Humidity) will read the respective parameters continuously. in between if I press '...
5
votes
1answer
593 views

What does []() argument in function mean?

I am working in ESP8266 AsyncWebserver library and have been using this [](parameter) as an argument to some functions as shown below but does not really know what it means. Being a neophyte I am ...
0
votes
2answers
57 views

using different variables in a function

I have a function SetTFgr (float T, int FGr) to set the time and filtergrade of my LED enlarger. It works without a problem and changes the values of T or Fgr according to the buttons I press. Both T ...
1
vote
2answers
48 views

Use of “static” with “RTClib”

I've got a question concerning the Arduino library "RTClib" by Adafruit and the use of the word "static". Here you can see an excerpt from the example provided for the pcf8523 real-time clock: #...
0
votes
1answer
31 views

Activating a defined macro in a class from main.cpp

Sorry if this question been asked. I'm trying to activate certain function in a class using a macro defined in the class from main.cpp. I'm using jrowberg MPU6050 library if that matters. main.cpp #...
0
votes
1answer
72 views

How to get the free/used space on a SD card and transmit it

I'm using this block of code to read and sum up the bytes of all the text files I have on an SD card: long get_sd_memory_taken() { File dir = SD.open("/"); long sd_memory_taken; int c = 0; ...
1
vote
1answer
35 views

Unable to understand the acquisition of data from Magnetometer HMC5883L and Accelerometer ADXL345

Below are the X,Y,Z registers for HMC5883L. while this is the Arduino code for HMC5883L to acquire X,Y,Z reading. If you look at this code, we do not mention the X, Y, Z address specifically. ...
-1
votes
1answer
27 views

Ultrasonic Sensor as Unlock Sensor

Is it possible to use ultrasonic sensors maybe HC SR04 type as unlock sensors? I'm figuring out if it can replace matrix keypad? For example 6 HC SR04 are used to be an input sensor waiting for a ...
0
votes
2answers
42 views

If condition not working as expected

In the last condition in else if (see code marked with ***), I am not getting my screen with the laser/specklke fail, if both failflag 1 and failgflag 5 is there, however it shows me laser fail ...
0
votes
1answer
16 views

Update class attribute with attachInterrupt

I want to refactor this code /* YF‐ S201 Water Flow Sensor Water Flow Sensor output processed to read in litres/hour Adaptation Courtesy: www.hobbytronics.co.uk */ volatile int flow_frequency; // ...
0
votes
1answer
70 views

Remove blocking delay() toneMelody function?

I would like to change the delay() into a nonblocking function in the code below. I've implemented it (a part of a tutorial from arduino.cc) in my code, but the delay() is blocking the rest of my code....
0
votes
0answers
36 views

Serial Monitor shows random texts While Reading Data from RTC DS3231 with Arduino Uno

I tried to set time on a RTC DS3231. After Uploading it with Arduino IDE, I try viewing the output in the Serial Monitor. However, if I start viewing the Serial Monitor, It starts showing encrypted ...
0
votes
1answer
30 views

How to split a *char and pass to a function needing uint8_t?

I have a requirement where an event has char *newvalue. void event(char *newValue) { //Code here } newValue is 2 digits. If it's 1-9 it is " 1" " 2" and 10+ is "10" "11" etc. It also can contain ...
0
votes
2answers
43 views

Weird behavior of variables when replacing for loops with if statement

See the picture of serial monitor showing I get a large number, 4 billion, when I multiply two called functions together. It always happens after 53 if I change the amount the if statement counts to. ...
0
votes
1answer
44 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 ...
1
vote
2answers
81 views

Is there a way to make a function take an exact number of clock cycles?

Is it possible to use something like a compiler directive to pad a function with do nothing instructions so that as you add lines of code or take them away it always executes in the same amount of ...
-1
votes
2answers
70 views

How do I run a function every 10th time through a loop?

I currently have a function that poles all my sensors every time through it's loop, but I want to pole one of the sensors only every 10th time. Currently there is a 10 millisecond delay at the ...
0
votes
2answers
101 views

Replacing large lookup table with switch statement

My arduino needs to take a 14-bit number and convert it to a 10-bit number. Can't use a formula for it since the data is quite random. So I created a lookup table with 2^14 elements, each containing a ...
0
votes
0answers
48 views

Esp8266 SD card read from inside of class

This is now my 3rd attempt at being able to read this sd card from within the Esp8266webserver. I have made a class WebServer, and would like my sd card to contain my site. What throws me off, is I am ...

1
2 3 4 5
18