14

What are the generally practiced methods for the optimization program memory usage? First, note you are searching for ways to lower SRAM memory. This contains global (variable) memory and heap space (dynamic memory + stack memory). Avoid memory gaps, by not using dynamic memory (with free/malloc/new). Avoid using the String class. Avoid global memory in ...


7

I just want to add a single bullet to Michel Keijzers’ excellent answer: think about every single item you are storing in memory and ask yourself the question: do I really need to keep this in RAM? It may sound silly to state what many would consider obvious, but we have seen here many instances of novices who do not take this into consideration. As a ...


4

What are the generally practiced methods for the optimization program memory usage? (nb. as per Edgar's comment I emphasise that this is about using PROGMEM more efficiently.) If you can replace code with a table whose size is ≤ the lines of code, do it. Instead of using a sequence of ifs, find a way to collapse the procedure into a table Use tables of ...


2

The Serial.flush() is doing nothing. It delays until all bytes have been sent out of the UART. Since nothing has been sent it's not got anything to wait for. The delay after the available call is very bad practice. It's a really really bad way of dealing with serial reading. You should read this for a better understanding of serial communication.


1

So you want your program to react to both MQTT and serial messages. You wrote this snippet: if (topicStr.equals(lightTopic1) || Serial.available() > 0) { if (payload[0] == '1' || data = q) { digitalWrite(LED2, HIGH); } else if (payload[0] == '0' || data = w) { digitalWrite(LED2 , LOW); } // ... } Other than a couple of ...


1

You can print the value as it is: Serial.println(state); This will print the the ordering number of the enum, but you can specify the value as any number or char. enum States { SLEEP = 'S', AWAKE = 'A', CRAZY = 'C' }; Now if you print it with cast to char Serial.println((char) state); it will print a character, which in my opinion is much better then ...


1

I didn't try myself, but in the documentation it shows the MAX value is 2,147,483,647, which is 2^31-1. The MIN value I expect is -2^31, thus -2,148.483.648. Wondering what you mean by 'without success'. Yes this is a valid approach. A 'perfect' random generator should be able to generate all values with an equal distribution. Since the values are within [-...


1

Initializing a global is appropriate if you know in advance that it should always have a given value at startup. The compiler will generate a globals image in ROM that will be copied into RAM before any of your code is executed. Safe to assume compiler will initialze? The compiler will initialize to 0, a global not specifically initialized by you. Let's ...


1

Yes, you can use those pins like regular digital pins on the Uno. They are numbered 0 and 1. That is... provided you do not try to use Serial.


1

Programming a bare ATtiny85 IC needs either another Arduino or an AVR programmer Programmer $4-$7 Something like the Pololu AVR Programmer v2.1 can be bought for $7 and used with the free Arduino development software (IDE). I have used this to program an ATtiny85. This is what I would suggest, because a programmer is the most versatile solution. Even ...


1

It's screaming on you: sketch_jun13a.ino:7:11: warning: invalid conversion from 'const char*' to 'char' [-fpermissive] char x = "0"; ^~~ sketch_jun13a.ino: In function 'void loop()': sketch_jun13a.ino:21:36: warning: comparison with string literal results in unspecified behavior [-Waddress] if (Serial.available () && (x == "0")) ...


1

If you're using a pointer then there's no limit to what that pointer can point to. The way I see it you have two sensible choices: Point to a default value This doesn't have to be in your array. It can be anything that is an int[3], since that is what your array consists of. int[3] nothing = {0, 0, 0}; EXCLUSIVE_COLOR = nothing; This means that it's ...


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