Hot answers tagged

7

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. Since it is in global scope, and not explicitly initialized, it is implicitly initialized to all bytes zero. leds[0] = {0,0,0,0,0}; Here, you are trying to give ...


6

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 ASCII code for the double quote (") 0x33 is the ASCII code for the digit 3. 0x44 is the ASCII code for the uppercase letter “D” etc.


5

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: Incorporated great improvements and a fix from Edgar in the comments. String overload. Display baud rate suggested by mehmet #define DISPLAY_DEVICE Serial #define ...


4

A pointer is just a pointer. It's not an array. On 8 bit Arduinos the memory address range is a 16 bit value, so a pointer will always be 2 bytes. You need to return two values from your function - the buffer pointer and the length of the buffer. This is usually done by passing an extra integer pointer parameter: unsigned long w; void setup() { Serial....


4

There is no problem here. Only the compiler is a bit smarter than you anticipated. It sees, that you are not using arr anywhere, so it just optimizes it out. There are two ways to prevent that, if you really want to: I think you can use flags to tell the compiler, that this shouldn't be optimized out. I'm no expert in this, others might know more about this ...


4

Here's an example of how to do it: jump_table.ino int func1(int arg) { return arg + 1; } int func2(int arg) { return arg + 2; } int func3(int arg) { return arg + 3; } int func4(int arg) { return arg + 4; } int func5(int arg) { return arg + 5; } int func6(int arg) { return arg + 6; } int func7(int arg) { return arg + 7; } int func8(int arg) { return ...


3

On the AVR platform the char type happens to be signed, and it can store numbers in the range [−128, +127]. Thus, when you write char bar = 128; You are asking to store in bar a number that does not fit. It then gets reduced modulo 28 into the value that does fit, namely −128. For the kind of manipulations you are trying to make, I would recommend you use ...


2

The easier way to simply the code is to use strcpy to create a buffer that is 1 byte longer than the length and then terminate it with \0. void messageHandler(char *topic, byte *payload, unsigned int length) { char buffer[length+1]; strcpy(buffer, (const char*) payload); buffer[length] = '\0'; Serial.println(buffer); int matched = strcmp(buffer, &...


2

You seem to already understand that it's not null-terminated and that's why it's not working the way you expect. So, I'll take a different tact for "how to fix it". You can simply not treat the payload as a string, and instead use memcmp, as in: if (length == 9 && memcmp(payload, "ravenclaw", 9) == 0) { memcmp behaves similarly ...


2

add r16, Z+ You probably meant something like add r16, memory[Z+] However, the AVR is a RISC processor. It has instructions to address the memory, and instructions to do arithmetics, but it has no “complex” instructions that both address the memory and do arithmetics with the addressed data. So you have to use separate instructions to: Load (ld) the data ...


2

Storing the data into arrays is not an end in itself. The question is: what do you want to do with these arrays? The way to proceed depends on that purpose. If you want the data acquisition (analogRead()) and the processing (computation and printing) to proceed in parallel, then you will need the arrays for buffering the data between those two processes. As ...


2

There are multiple problems here: if(Hexa_Val[7] = 0xFF) First of all, = is the assignment operator. You are setting Hexa_Val[7] to 0xFF. If you want to compare for equality, you should use ==. Second problem, The value 0xff will never be displayed, because you are replacing it by zero. This byte will then count 0xfd, 0xfe, 0x00, skipping 0xff. If you want ...


2

Two-dimensional arrays come in two "flavours". Actually, multi-dimensional arrays are possible in any combination of these. All elements in a rectangular grid, at least from the abstract view of the programming language; A one-dimensional array of one-dimensional arrays. If you declare: byte array[n][m]; then you have reserved space for "n ...


2

The error message is quite explicit: argument of type "const byte (*)[8]" is incompatible with parameter of type "const byte *" If you want to pass SPACED_STRIPES to the method, it is going to be passed as const byte (*)[8], i.e. pointer to arrays of 8 byte. You can just set the parameter type accordingly: void CSMatrix::...


1

Majenko's answer explains things and shows how to fix your code, but the solution with static buffer inside the function is not common. Common is to have int readBuffer(unit8_t* buffer, size_t size). The parameters are the buffer provided by the caller and the size of that buffer. The return value is the count of bytes written by the function into the buffer....


1

To store a 2 character string you need a 3 byte array, not a 2 byte array. This is because in C a string consists of the actual string data and a zero ("NULL") byte at the end to indicate where the end of the string is. So you would need: char Hex_Array[3]; so it can store, for the number 0x69: 69\0. Otherwise you overrun the array and corrupt ...


1

#include <DES.h> DES des; byte in[8]; String input; char buf[30]; void setup() { Serial.begin(9600); Serial.println("Hello!"); } void tdesTest() { byte out[8]; byte key[] = { 0x3b, 0x38, 0x98, 0x37, 0x15, 0x20, 0xf7, 0x5e, // key A 0x92, 0x2f, 0xb5, 0x10, 0xc7, 0x1f, 0x43, 0x6e, // key B 0x3b, 0x38, 0x98, 0x37, 0x15, ...


1

From your comments I think I understand what you are after. So, assuming you have read some string into a String object called input and you have an array in[8] to populate you can: Clear the in[] array to a preset state Copy the string content into in[] As code: memset(in, 0, 8); // Erase the contents of in[] input.toCharArray((char *)in, 8); // Copy up ...


1

A 2D array would be passed as const byte frames[][8]. However you really don't need the complexity of a 2D array - you can do it with a 1D array. Your array would look like: const byte SPACED_STRIPES[] = { 0b11000110, 0b10001100, 0b00011000, 0b00110001, 0b01100011, 0b11000110, 0b10001100, 0b00011000, 0b01100011, ...


1

I have to remove the pos++ from if statement to have digitalWrite working again according to captured temperature: if (pos < DATA_SIZE && current_time >= scen1[pos].time) { if (temperature1 < scen1[pos].temperature) { digitalWrite (relay1, HIGH); } else if (temperature1 > scen1[pos].temperature) { digitalWrite (...


1

When working with Arduino, cplusplus.com is your friend. Scroll down and look on the left side under (string.h). Lot's of great char functions there. Other useful functions such as iota() - cplusplus.com. Here's one way to accomplish the parsing of the input data. // Sketch uses 2064 bytes (6%) of program storage space. // Global variables use 323 bytes (15%)...


1

not going to pretend i understand why all my keypad numbers are 48 higher than the number printed on the keypad but: int key2 = key -48; works


1

Ah, one of my friends pointed out the issue. It's a scope snag: chunks is allocated on the stack in get32BitInt By returning a pointer to chunks, you are pointing to memory that is deallocated. Think of it as pointing to a member variable of a class that has already been destroyed when you try to dereference deallocated memory, bad things can happen. ...


1

My DaquinOscope https://www.daqarta.com/dw_rroo.htm uses the open-source DaqPort sketch https://www.daqarta.com/dw_rraa.htm to sample in batches, then transfer the data to the host in one high-speed blast. It takes 1024 total samples, which in your case of 2 channels would be 512 per channel. It stores only the raw data, unscaled... the host is the place ...


1

You can create two arrays, e.g.: #define MAX_LENGTH 20 volatile float _gauge0[MAX_LENGTH]; volatile float _gauge1[MAX_LENGTH]; volatile int _filled = 0; The _filled value shows that _gauge0 is filled from 0 upto (excluding) _filled. So when adding two values you use: _gauge0[_filled] = some value; _gauge1[_filled] = some_other_value; _filled++; After ...


1

I'm still not entirely sure what you want to achieve, but maybe this will help: You have a global variable int weight, and in int Sampling() you create another int weight = scale.get_units() which you give a value. That second variable is only accessible inside of Sampling(). If you want to use it elsewhere for storing or in other functions, change: int ...


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