1/5/2024 0 Comments Arduino simplesynth sketch![]() So I want to ask this community if you could help me find something, point me in the right direction. I've been doing research for months now but the options are just to overwhelming. The way it works best for me is to do a type of project I'm familiar with and just learn the rest along the way. Once it Verifies, upload the new image and see if it still works.Hi, I'm a self-taught dev/programmer (back-end/app/VST, c, c++, audio and basic electronica) and I want to get into embedded. This is the advantage of making a copy of the library, I can refer to the original to see what I need to add back. The errors will tell you what files and lines to look at, follow them and fix anything it complains about. My first try I got a lot of compile errors because I removed too much code, or removed a variable definition and missed the code where that variable was used. Now in your sketch, change the include and class names to match your new library and do a Verify. ![]() Next, I opened every file included under the myUTFT folder and gave them all the same treatment. I also removed methods for features my lcd does not support, just as the on/off and contrast methods. I then read each function and looked for code I don't need, for instance the LCD I'm using has an include files that sets "display_transfer_mode = 8", so I don't need any code that uses any other display_transfer_mode values, so I removed those blocks of code. I only plan on setting colors by the "word" named constants and not by RGB bytes, so I removed "setColor(byte r, byte g, byte b)" and "setBackColor(byte r, byte g, byte b)" functions. I also removed some overloaded functions. ![]() h file, renaming UTFT to myUTFT and removing unneeded defines and functions. UTFT has a note about some undocumented methods, and these appear to be used internally, so I left them. Finally, there's a list of class methods, and I removed the ones I'm not using. I could have left these as-is, but decided to brute-force everything and removed all but the AVR ones for the Arduino. ![]() Next there are some "#if defined"' lines for the different micro-controllers supported. I removed everything except the ones I'm using. First I saw there's a list of defines for all the different LCDs and chips supported. Now the hard part, removing code! I started with myUTFT.h and started at the top, reading the code. This gets me a totally new library and class that won't ever cause a conflict in the Arduino environment. Next, I opened myUTFT.h and myUTFT.cpp in a text editor and replaced all UTFTs with myUTFT. First off, I went into the arduino/library folder and made a copy of the UTFT folder and named it "myUTFT", then renamed UTFT.h and UTFT.cpp to myUTFT.h and myUTFT.cpp. I'll try explain how I went about this so that you can apply it to any library. Even after using UTFT's memorysaver.h I was able to save over 5K of additional space by removing all the code to support multiple LCDs and by removing class members that I'm not going to use. Doing this requires a lot of code reading and tracing to determine what you really do have to keep, and some trial and error to get it all to compile and work. It supports several LCDs and has a lot of drawing functions. One of the libraries I'm using is the UTFT lcd library. This allows me to test the i2c methods while watching the serial port, but sacrifices the LCD display.Ī more extreme and brute force method of reducing the program size is to make a copy of any large complex libraries and remove any code you aren't going to use. You can define it in your code, before including the library, to disable these functions if you do not need them and reduce the compiled size slightly like: #define DHT22_NO_FLOAT #include You can also use #defines in your code to switch out debugging and production code, such as: //uncomment this for dev mode //#define DEVMODE 1 void setup() In this case, I don't initialize the LCD, and later in the code I also don't use LCD drawing functions. By default DHT22_NO_FLOAT is not defined so the code is included. At line 35, 57, and 65 you can see "#if !defined(DHT22_NO_FLOAT)". An example can be found in one of the DHT22 sensor libraries to disable the code that returns float values. It allows you to turn features on and off as needed. Conditional compilation is one method you can use to save program space without removing code.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |