Hi, (Sorry for my terrible english) i am new in the programming. I have searched this topic but could not find. I want to learn - is there any way to use arduino libraries (auch as LiquidCrystal_I2C or DHT and etc.) in arduino sketch which has not included setup() and loop(). For example: #include <LiquidCrystal_I2C.h> #include <Wire.h>
LiquidCrystal_I2C lcd(0x27 , 16 ,2);
int main()
{
lcd.init();
lcd.backlight();
lcd.setCursor( 0 , 0);
lcd.print("Hello World");
while(1)
{
asm("");
}
}
it does not work in this way. Someone said there must be included init(); in the main, but when i included init() - it used same memory amount with sketch with setup() and loop() functions.
is there any other way? thank you for replys.
It seems odd, but you are free to have your very own main() and enjoy none of what the “real” main() function provides, or just copy the things it does and obvsly where it then loops the loop so to speak you do you thing.
because in my code, only the user interface thing (i am using GLCD) covering 78 - 80 % of the memory, and if it is continue in this way i will have no place for actuators. so i was looking for ways to get rid of extra things which covering memory. i found that using main(); and port manipulation covers less memory, so i decided to code in that way, but then i noticed libraries are not working
i dont know exactly how many characters i have, there are 4 menu topics and each menu there are 3 menu topics inside and inside that topics there are also some setting walues, in some menu parts it gets number from Keypad, turns it to number, in some parts it gets from potentiometer , and it cordinates menu with rotary. The strings stored in program memory i guess. May be my sketch takes more space than usual because i am not a good programmer and my code is not regularly typed , idk.
Hi sir, my guestion is not about exact any arduino type or exact any code sketch. My guestion is for general purpose, that is why, I did not think it is necessary to write them all.
Why would it take less memory when what you have done by using main() and calling init() which is basically what the normal Arduino main() function does ?
You will not be able to use most Arduino libraries without having your sketch also include the "overhead" you see when you use setup() and loop()
Graphics LCD libraries are quite large compared with ... nearly anything else in the Arduino environment. They are FAR larger than the setup/loop/init overhead.
Size growth isn't "linear" compared to the amount of code in your sketch. Just because you've used 78% of space for a framework that does LCD stuff doesn't mean that the 20% space remaining isn't enough to do low-level actuator stuff.
You may want to look for a smaller GLCD library, or a bigger Arduino.
Just define your own main() function. Doing this will override the Arduino main() function and totally mess up just about anything that you want to do using many if not most libraries, but it is possible.
Smells strongly of XY. And, if you're at the point of messing around with such things, either your code is horribly bloated or you need to move to more capable hardware. Look into an ESP32 or ARM-based platform.