How to use Arduino libraries without setup() and loop()

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.

Your post was MOVED to its current location as it is more suitable.

Why exactly do you want to avoid using setup() and loop() ?
What advantage do you see in doing so ?

Because an emtpy setup and loop take no space.

Just get with the progarm - stop worrying and learn to love the Arduino setup/loop thing.

a7

Here is the main.cpp code used by the Arduino IDE:
https://github.com/arduino/ArduinoCore-avr/blob/master/cores/arduino/main.cpp

Do you have a specific reason for wanting to eliminate setup and loop?

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.

a7

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

How many strings of characters do you have in your sketch and where are they stored ?

Yeah so maybe some of what the included main() function does will be necessary.

I think @UKHeliBob's comment could be generalized: if you are truly running short on rexources you probably want to look elsewhere for true savings.

a7

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.

Good guess... either in SRAM memory or flash memory.
A must read

Hi, @turqaym
Welcome to the forum.

Please read the post at the start of any forum , entitled "How to use this Forum".

This will help with advice on how to present your code and problems.

Can you please tell us what you project is?
What does it do and what is the hardware involved?
What model Arduino are you using?

Thanks.. Tom... :grinning: :+1: :coffee: :australia:

When you did include the init() function did the sketch work correctly?

Yes it did, but as i said, i think it should cover less memory than usual, but it did cover same amount of memory

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 ?

  1. 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()
  2. 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.
  3. 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.
  4. You may want to look for a smaller GLCD library, or a bigger Arduino.

Take a break.
Get a beer if you are so inclined.
Watch this vid: https://www.youtube.com/watch?v=-XPrSScamXc

I you do not want to use the Arduino paradigm, then don't.

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.