Denis_Bacellar

Good afternoon friends!!! I have an 8 channel relay module. I am trying to make code separately for each channel to work independently. I tried to do it in a way that is widely used in industries, in routines. That is, a Sketch for each channel. For each channel to work independently. But it is giving many different errors. Can Arduino run in this more organized way? Help me solve this please!

Primeiro_Programa_no_Arduino_Mega_Rotina1.ino (188 Bytes)

Primeiro_Programa_no_Arduino_Mega_Rotina2.ino (185 Bytes)

Primeiro_Programa_no_Arduino_Mega_Rotina3.ino (183 Bytes)

Primeiro_Programa_no_Arduino_Mega_Rotina4.ino (183 Bytes)

Primeiro_Programa_no_Arduino_Mega_Rotina5.ino (183 Bytes)

Primeiro_Programa_no_Arduino_Mega_Rotina6.ino (184 Bytes)

Primeiro_Programa_no_Arduino_Mega_Rotina7.ino (182 Bytes)

Primeiro_Programa_no_Arduino_Mega_Rotina8.ino (184 Bytes)

What makes you think this is a bootloader issue?

Using a separate program for each channel (at least in the simple sort of case you've described) is not reasonable coding practice on embedded systems where there is no OS. Only one program runs, and compiling a sketch only generates one program - when there are multiple .ino files in one folder, the IDE combines them all into one file, and compiles that. Which of course fails, because you have 8 definitions of setup() and 8 definitions of loop(). Multiple .ino files are useful for separating code into multiple files to make it easier to read and maintain, but they are not programs, they are pieces of one program.

The closest approach would be to create a class for the relay, and in the main sketch, create 8 of them - but for such simple code, this probably makes the program more complicated, not less...

One could also have a function that takes the relay number as an argument or something - an approach like that often makes a lot of sense in embedded systems.