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.

C++ is the standard language used to program the Arduino IDE. Most Arduino code online is written in this language.

C++ is one of the most popular coding languages available, being highly cross-platform. However, transferring Arduino code to PC code (and vice versa) is very hard, even when ignoring the fact that your computer can't run a motor. For example, in C++ code, the first thing to be called is main. In Arduino C++, main is still called, however, the Arduino libraries are called, not your sketch. Those libraries then call setup and then loop repeatedly after finishing all the initialization tasks they must perform before the Arduino can run the code of your sketch.

It is pronounced "C plus plus."

1059 questions
9
votes
2 answers

How can I pass an object as a parameter to a function?

I am making a tiny game, and want to store high-scores. I made a Highscore-class in the top of the sketch file, like this: class Highscore { public: String name; int score; String toString() { return this->name + " - " + (String)score; …
krystah
  • 195
  • 1
  • 2
  • 6
7
votes
1 answer

Arduino sizeof Servo array objects is.. wrong?

After searching for a quite long while over the internet, I have no choice but to try asking someone if they can explain me this apparently strange situation. I'm doing some tests using some servo motors, trying to move them almost together using…
briosheje
  • 173
  • 2
  • 6
3
votes
2 answers

Receiving garbled `char` array returned by a function

I return a char[300] array from a function. If I intialize a char* variable with it, the return is garbled, but not if I append it to a String. What gives? const char* post2 = uploadHourCsv(timeNow,pulseChangeHour) ; String postS2 = ""; …
tony gil
  • 362
  • 1
  • 7
  • 26
3
votes
3 answers

Using special Arduino "boolean" Data Type instead of standard "bool" data type

There is a special, non-standard Arduino data type called "boolean". How does it compare with the standard C++ data type "bool", and what are the reasons to use one or the other? If they are identical in usage, why do both exist, and which one is…
user34607
2
votes
2 answers

Using Adafruit RTClib without fragmenting the heap

I'm getting ready to add DS1307 support to my Arduino app, and was horrified when I looked at the sourcecode for the RTC_DS1307 class in Adafruit's RTClib library... DateTime RTC_DS1307::now() { uint8_t buffer[7]; buffer[0] = 0; …
Bitbang3r
  • 523
  • 1
  • 3
  • 11
2
votes
1 answer

Seting up registers in Samd based arduino board

I'm trying to setup the BOD33 for Samd51 MCU in th .ino file as a first thing, even before the #include lines in the .ino // Define the base address for t_SUPC #define T_SUPC_BASE 0x40001800UL // Define the offsets for t_BOD33 and t_STATUS #define…
Dan Neb
  • 21
  • 1
2
votes
1 answer

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 to a router. Background I want to read values…
Jeremy
  • 123
  • 4
2
votes
1 answer

Where to store AES key on Arduino board

I'm working with this library AES lib so everything works I can encrypt/decrypt data. But now I'd like to know what is the best way to store my aes private key ? My boars is a personnal board build with an samd21 cortex M0+ my board doesn't have the…
simon
  • 133
  • 5
2
votes
3 answers

When are global constuctors executed?

Apologies if this has been discussed before but I couldn't find anything. I have written a simple LED class. For illustration (it is actually a bit more complex) but it goes something like; class LED { LED(byte pin); private: int…
Rob W
  • 138
  • 8
2
votes
1 answer

if(val == 0) being ignored when it contains another nested if() statement

The issue: In the following example even though complexManoeuvre == 3, Serial.print(CTA5: "); ... is executed. void loop() { if(complexManoeuvre == 0) { if(timeisup == true && goingForwards == 1) { // If time is up while going forward,…
lsbyte
  • 21
  • 2
2
votes
2 answers

how does c++ understand which function must to use?

in this code: void AdptSendReply(const char* str) { string s(strlen(str) + 2); s = str; AdptSendReply(s); } void AdptSendReply(const string& str) { string s(str.length() + 2); AdptSendReply(s); // use the next one } void…
2
votes
2 answers

OBOE: Need help understanding, possible type conversion issue

I have an algorithm that its main purpose is decoding, converting, or what have you a string of uppercase letters (A-Z) into a number. This is almost like converting a base 26 number into base 10, however I believe that a base 26 number encoded…
James Little
  • 121
  • 3
2
votes
2 answers

stop running a certain function when sensor picks up something and return to where it stops?

i have a question on how to program a certain sequence for my robot. lets say if i would to program to make it run from position a to b, i have a sensor attach to it that should it detect x, it would perform an action called y at the position where…
user38950
  • 21
  • 1
2
votes
1 answer

Error: "invalid use of incomplete type" and "forward declaration"

I have the following errors trying to use a TFT library function inside my library. My library uses the pointer to an instance of the TFT library in the constructor, as well described there: Basic C++ programming, how to pass constructor argument…
2
votes
0 answers

How to implement a priority queue

I was wondering if I would be able to use specific parts of the c++ library for my arduino sketch. For example the arduino library has a queue array but I wanted to use a priority queue for my sketch and I am unsure how to modify the queue header…
Major Ben
  • 21
  • 2
1
2 3 4 5 6