Skip to main content
27 votes

Why does Serial.print print only a value for 0-84 for a 100 integer array?

It's because you're using exit(0). That turns off interrupts and goes into an infinite loop. However, serial printing is first placed into a buffer, and each character is then removed from that ...
Majenko's user avatar
  • 105k
13 votes

Returning an int array from a function

There are several ways to achieve what you want: The way that does not work Did you try to compile the code you gave in the question? Then you probably noticed it does not compile. I tried and got: “...
Edgar Bonet's user avatar
  • 43.1k
10 votes
Accepted

Initializing Array of structs

led h_red = {0,0,255,0,300}; Here, you are defining a variable, and at the same time giving it an initial value. This is called an initialization. led leds[LEDS]; Here you are defining an array. ...
Edgar Bonet's user avatar
  • 43.1k
9 votes

Sizeof variables and Due's RAM

sizeof doesn't return the number of elements. It returns the number of bytes. Since they are uint16_t arrays each element is 2 bytes - hence twice the size. The reason your last number is only 40928 ...
Majenko's user avatar
  • 105k
8 votes

for loop running infinitely

After a chat with OP, it turned out this was a more complex issue, probably a memory overrun. This cannot be seen in this small snippet, but the whole program is using memory extensively (global ...
jfpoilpret's user avatar
  • 9,132
7 votes
Accepted

Is it possible to have an array of int arrays?

Yes you can have arrays inside arrays. The array would be declared as: int arrayName [ x ][ y ]; where x is the number of rows and y is the number of columns. The example below declares and ...
sa_leinad's user avatar
  • 3,188
7 votes
Accepted

How to convert array of chars to array of ints?

If you have a C string containing ASCII numbers with a common delimiter (comma in this case) you can use the strtok() function to split it into individual strings. Then you can use atoi() to convert ...
Majenko's user avatar
  • 105k
7 votes

Replacing several pinMode() and digitalWrite() pins with an array

the correct way to store the pins as an array Your array initializers are almost right; you just need to separate the values with commas: digitPins[] = {13, 12, 11, 10}; segPins[] = {2, 3, 4, 5, 6, ...
JRobert's user avatar
  • 15.3k
7 votes

Lowest memory consumption for arrays

If I dare suggest an unorthodox solution... I suggest you store the times as “float11” floating point numbers. Michel Keijzers' solution is nice, but there is an issue with the choice of the time ...
Edgar Bonet's user avatar
  • 43.1k
7 votes
Accepted

How to get char array's length

The function I think you are looking for is strlen - STRing LENgth. It counts the number of characters in a string up until it finds the "NULL" end of string marker. Serial.println(strlen(t));
Majenko's user avatar
  • 105k
6 votes
Accepted

Returning an int array from a function

I have a function that needs to return 3 int values. In the interests of completeness I'll suggest another method. Let's assume that you really need 3 values and not 300. void foo (int & a, int ...
Nick Gammon's user avatar
  • 38.2k
6 votes

How can I concatenate multiple byte Arrays into one Array

You can concatenate with memcpy. You just need to set the pointer at the right place inside the c1 array. memcpy(c1, a1, sizeof(a1)); memcpy(c1+sizeof(a1), a2, sizeof(a2)); memcpy(c1+sizeof(a1)+...
gre_gor's user avatar
  • 1,682
6 votes
Accepted

Max length of char arrays?

The main issue with your code is: sizeof(s) That doesn't return the string length - it returns the size of the char pointer - which is two bytes (on an 8-bit system, 4 on a 32-bit system). Instead ...
Majenko's user avatar
  • 105k
6 votes
Accepted

How can I initialize an array of objects in setup?

As Craig wrote, the declaration of an class typed array will call the default constructor of the class, which is the one without any arguments. The class, that you use, does not provide a default ...
chrisl's user avatar
  • 16.3k
6 votes

Printing the array using print and serial write function in Arduino Uno

Serial.write(some_byte) writes a byte on the serial output. The Arduino serial monitor tries to interpret the bytes it receives as text: 0x11 is a control character, displayed as “□” 0x22 is the ...
Edgar Bonet's user avatar
  • 43.1k
5 votes
Accepted

Iterate an Object Array

You are not creating an array of references, you are creating the array from the objects; they are being copied. You can see that this by moving the line (and adding an equals) Train trains[...
uint128_t's user avatar
  • 819
5 votes

Does int array[100] = {0} construct work on Arduino?

This construct does work in Arduino IDE. In fact, = { 0 } is one of the iconic idioms of C language. It can be used to zero-initialize an object of any type in C. In C++ things are a bit more ...
AnT stands with Russia's user avatar
5 votes

Image Breakdown

240 by 320 pixels. That's 76800 pixels. In your example it looks like you want 3 bytes per pixel, so that's 230400 bytes. An Arduino Mega has 8K bytes of SRAM memory. There's enough room in the ...
Delta_G's user avatar
  • 3,270
5 votes
Accepted

Image Breakdown

I presume you are trying to create a system that has one image stored, and want the image to be available without needing an SD card reader on the system. If the logic of your program is small enough ...
James Waldby - jwpat7's user avatar
5 votes
Accepted

Why does this array have stored values in it even though I have not put any values in it?

The values haven't been "put" in the array. The array has been located in memory where those values (left over from some earlier operation, possibly as part of a function's stack frame) happen to be. ...
Majenko's user avatar
  • 105k
5 votes
Accepted

Sending >255 bytes array to arduino

You use type byte for the variable ndx. Type byte is 8 bits, so the max value is 255. The variable ndx is incremented and after 255 it continues counting from 0.
Juraj's user avatar
  • 18.1k
5 votes
Accepted

Help with AlphaNumeric array

All of those "A1" "A2" pins have other numbers that go with them. The A1 or A2 is #defined in the core to be some number. You can just use A1 or A2 and it will work. For example, try this line and ...
Delta_G's user avatar
  • 3,270
5 votes
Accepted

Why does a variable size struct not compile in the Arduino IDE?

Flexible array member is a C feature. It does not exist in C++. On top of that, the way you use it to declare and initialize a static struct of flexible size is non-standard even for C. However, GNU-...
AnT stands with Russia's user avatar
5 votes
Accepted

HardwareSerial Indexing Array

your code makes copies of Serials into items in the array of HardwareSerials. To use the original Serial objects, store and use pointers. HardwareSerial* Serials[]={&Serial,&Serial1,&...
Juraj's user avatar
  • 18.1k
5 votes
Accepted

Setting an array pointer to null on declaration

Here is a full example that shows you all thing things you have been asking over the past few days: int colors[][3] = { {255, 0, 0}, {0, 255, 0}, {0, 0, 255} }; #define NCOLOR (sizeof(...
Majenko's user avatar
  • 105k
5 votes
Accepted

How to convert a String to Hex array

I don't know anything about the particular display, but based on the information provided I hope this is at least shows the foundation of one way you could approach a final solution. Update: ...
voidPointer's user avatar
4 votes
Accepted

Works with gcc, not with Arduino. error: taking address of temporary array

It is quite right, using that kind of syntax is not allowed. It's a bit of a pain, but it's ok since there is an alternative method - kind of a "trick" if you will. That trick is to use a string, not ...
Majenko's user avatar
  • 105k
4 votes
Accepted

Does int array[100] = {0} construct work on Arduino?

I'm used to this way from my desktop C++ programming practice: int array[100] = {0}; I couldn't find any info on whether or not this construct works on Arduino. The = {0} has no actual effect. ...
Majenko's user avatar
  • 105k
4 votes

Does int array[100] = {0} construct work on Arduino?

The GNU cross compilers for Arduino use C/C++ front-ends and meet some version the language specs. (Although that is a moving target, you can expect a recent IDE version will be compliant with a ...
JRobert's user avatar
  • 15.3k

Only top scored, non community-wiki answers of a minimum length are eligible