Help with iron man mask code

Hi all!
Novice in arduino here. :grimacing:
Before posting this I already went though all the other iron man mask code issues related posts and couldn't find anything that solved my problem.
This youtuber posted everything required to print and build an amazing IM helmet, including the code which doesn't compile.
So I asked chat gpt to help correct the errors and still nothing, so now I need to bother you guys.
I already installed the latest Servoeasing version and this is the original code:

#include <ServoEasing.h>

ServoEasing servoTop;
ServoEasing servoBottom;

const int action_pin = 2;
int location = 31;

// Adjust these values if necessary
int bottom_closed = 107;
int top_closed = 167;
int bottom_open = 20;
int top_open = 20;

void setup() {
    pinMode(action_pin, INPUT_PULLUP);
    servoTop.attach(9);
    servoBottom.attach(10);
    setSpeedForAllServos(190);
    servoTop.setEasingType(EASE_CUBIC_IN_OUT);
    servoBottom.setEasingType(EASE_CUBIC_IN_OUT);
    synchronizeAllServosStartAndWaitForAllServosToStop();
}

void loop() {
    int proximity = digitalRead(action_pin);
    if (proximity == LOW) {
        if (location > bottom_open) {
            servoTop.setEaseTo(top_open);
            servoBottom.setEaseTo(bottom_open);
            synchronizeAllServosStartAndWaitForAllServosToStop();
            location = bottom_open;
            delay(600);
        } else {
            servoTop.setEaseTo(top_closed);
            servoBottom.setEaseTo(bottom_closed);
            synchronizeAllServosStartAndWaitForAllServosToStop();
            location = bottom_closed;
            delay(600);
        }
    }
}

I really appreciate your help!
Best regards,
Flavio

Post the complete error message that you get.

Which board are you using? Did the youtuber use the same board?

Yes, I'm using Nano Every, as he advised to.
And these are the error messages:

/private/var/folders/6p/xtc1l3bs0g5dnjx7x7mjkwyc0000gn/T/.arduinoIDE-unsaved202427-41046-82pc4o.0r0yp/sketch_mar7b/sketch_mar7b.ino: In function 'void loop()':
/private/var/folders/6p/xtc1l3bs0g5dnjx7x7mjkwyc0000gn/T/.arduinoIDE-unsaved202427-41046-82pc4o.0r0yp/sketch_mar7b/sketch_mar7b.ino:19:14: error: a function-definition is not allowed here before '{' token
 void setup() {
              ^
/private/var/folders/6p/xtc1l3bs0g5dnjx7x7mjkwyc0000gn/T/.arduinoIDE-unsaved202427-41046-82pc4o.0r0yp/sketch_mar7b/sketch_mar7b.ino:29:13: error: a function-definition is not allowed here before '{' token
 void loop() {
             ^
/private/var/folders/6p/xtc1l3bs0g5dnjx7x7mjkwyc0000gn/T/.arduinoIDE-unsaved202427-41046-82pc4o.0r0yp/sketch_mar7b/sketch_mar7b.ino:46:1: error: expected '}' at end of input
 }
 ^

exit status 1

Compilation error: a function-definition is not allowed here before '{' token

They highlight these 2 lines:

void loop() {

void loop() {

And the very last }

Which board are you using, and is this error log complete?

Yes, this is the complete error log and I'm using the Nano Every.

Any insights?

Could you see something wrong?

The errors look like two .INO files are inside the same folder. The compiler will assume it should use all files in a folder, and if two files have "loop()" and "setup()" errors will occur. BUT it is plain to see only one filename.

I'm afraid this is greek to me :face_with_peeking_eye:

Check the opening and closing brackets match - same number of each .

You really need to get some coding experience , downloaded stuff is often full of errors or needs modifying before it will run or makes assumptions about your skill level

Thanks for your answer hammy. I build things, lots of them, using different materials and techniques but coding is beyond my possibilities and time availability.
I chose this project as a gift present for my son and, by the video, it was super straight forward: just copy the code, compile on arduino and the mask will be working.
I never expected to go through this hassle.
And, I REALLY ADMIRE who is capable of coding. Lot's of kudos for everyone with this skill.
For now I just need to solve this, as the mask is all ready and I'm overdue since my son's birthday was 2 days ago. Cheers!

No it is not. Did you install ServoEasing by ArminJo? This is the error (if you use your original sketch without editing):

In file included from C:\Users\user\AppData\Local\Temp\.arduinoIDE-unsaved202428-6320-s0bs6x.14tz\sketch_mar8a\sketch_mar8a.ino:1:0:
c:\Users\user\OneDrive\Documents\Arduino\sketchbook\libraries\ServoEasing\src/ServoEasing.h:886:2: warning: #warning You probably must change the line #include "ServoEasing.h" to #include "ServoEasing.hpp" in your ino file or define SUPPRESS_HPP_WARNING before the include to suppress this warning. [-Wcpp]
 #warning You probably must change the line #include "ServoEasing.h" to #include "ServoEasing.hpp" in your ino file or define SUPPRESS_HPP_WARNING before the include to suppress this warning.
  ^~~~~~~
C:\Users\user\AppData\Local\Temp\cchWExBa.ltrans0.ltrans.o: In function `setup':
C:\Users\user\AppData\Local\Temp\.arduinoIDE-unsaved202428-6320-s0bs6x.14tz\sketch_mar8a/sketch_mar8a.ino:17: undefined reference to `ServoEasing::attach(int)'
C:\Users\user\AppData\Local\Temp\.arduinoIDE-unsaved202428-6320-s0bs6x.14tz\sketch_mar8a/sketch_mar8a.ino:18: undefined reference to `ServoEasing::attach(int)'
C:\Users\user\AppData\Local\Temp\.arduinoIDE-unsaved202428-6320-s0bs6x.14tz\sketch_mar8a/sketch_mar8a.ino:19: undefined reference to `setSpeedForAllServos(unsigned int)'
C:\Users\user\AppData\Local\Temp\.arduinoIDE-unsaved202428-6320-s0bs6x.14tz\sketch_mar8a/sketch_mar8a.ino:20: undefined reference to `ServoEasing::setEasingType(unsigned char)'
C:\Users\user\AppData\Local\Temp\.arduinoIDE-unsaved202428-6320-s0bs6x.14tz\sketch_mar8a/sketch_mar8a.ino:21: undefined reference to `ServoEasing::setEasingType(unsigned char)'
C:\Users\user\AppData\Local\Temp\.arduinoIDE-unsaved202428-6320-s0bs6x.14tz\sketch_mar8a/sketch_mar8a.ino:22: undefined reference to `synchronizeAllServosStartAndWaitForAllServosToStop()'
C:\Users\user\AppData\Local\Temp\cchWExBa.ltrans0.ltrans.o: In function `loop':
C:\Users\user\AppData\Local\Temp\.arduinoIDE-unsaved202428-6320-s0bs6x.14tz\sketch_mar8a/sketch_mar8a.ino:29: undefined reference to `ServoEasing::setEaseTo(int)'
C:\Users\user\AppData\Local\Temp\.arduinoIDE-unsaved202428-6320-s0bs6x.14tz\sketch_mar8a/sketch_mar8a.ino:30: undefined reference to `ServoEasing::setEaseTo(int)'
C:\Users\user\AppData\Local\Temp\.arduinoIDE-unsaved202428-6320-s0bs6x.14tz\sketch_mar8a/sketch_mar8a.ino:31: undefined reference to `synchronizeAllServosStartAndWaitForAllServosToStop()'
C:\Users\user\AppData\Local\Temp\.arduinoIDE-unsaved202428-6320-s0bs6x.14tz\sketch_mar8a/sketch_mar8a.ino:35: undefined reference to `ServoEasing::setEaseTo(int)'
C:\Users\user\AppData\Local\Temp\.arduinoIDE-unsaved202428-6320-s0bs6x.14tz\sketch_mar8a/sketch_mar8a.ino:36: undefined reference to `ServoEasing::setEaseTo(int)'
C:\Users\user\AppData\Local\Temp\.arduinoIDE-unsaved202428-6320-s0bs6x.14tz\sketch_mar8a/sketch_mar8a.ino:37: undefined reference to `synchronizeAllServosStartAndWaitForAllServosToStop()'
C:\Users\user\AppData\Local\Temp\cchWExBa.ltrans0.ltrans.o: In function `_GLOBAL__sub_I_servoTop':
C:\Users\user\AppData\Local\Temp\.arduinoIDE-unsaved202428-6320-s0bs6x.14tz\sketch_mar8a/sketch_mar8a.ino:3: undefined reference to `ServoEasing::ServoEasing()'
C:\Users\user\AppData\Local\Temp\.arduinoIDE-unsaved202428-6320-s0bs6x.14tz\sketch_mar8a/sketch_mar8a.ino:4: undefined reference to `ServoEasing::ServoEasing()'
collect2.exe: error: ld returned 1 exit status

exit status 1

Compilation error: exit status 1

And if you follow the instructions in the error, your sketch will compile.

Sketch uses 7520 bytes (23%) of program storage space. Maximum is 32256 bytes.
Global variables use 165 bytes (8%) of dynamic memory, leaving 1883 bytes for local variables. Maximum is 2048 bytes.

I found the problem... you "pasted" your original sketch AFTER the "minimal.ino" sketch so you had TWO setup() and loop() inside ONE sketch... like this:

void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:

}
#include <ServoEasing.h>

ServoEasing servoTop;
ServoEasing servoBottom;

const int action_pin = 2;
int location = 31;

// Adjust these values if necessary
int bottom_closed = 107;
int top_closed = 167;
int bottom_open = 20;
int top_open = 20;

void setup() {
    pinMode(action_pin, INPUT_PULLUP);
    servoTop.attach(9);
    servoBottom.attach(10);
    setSpeedForAllServos(190);
    servoTop.setEasingType(EASE_CUBIC_IN_OUT);
    servoBottom.setEasingType(EASE_CUBIC_IN_OUT);
    synchronizeAllServosStartAndWaitForAllServosToStop();
}

void loop() {
    int proximity = digitalRead(action_pin);
    if (proximity == LOW) {
        if (location > bottom_open) {
            servoTop.setEaseTo(top_open);
            servoBottom.setEaseTo(bottom_open);
            synchronizeAllServosStartAndWaitForAllServosToStop();
            location = bottom_open;
            delay(600);
        } else {
            servoTop.setEaseTo(top_closed);
            servoBottom.setEaseTo(bottom_closed);
            synchronizeAllServosStartAndWaitForAllServosToStop();
            location = bottom_closed;
            delay(600);
        }
    }
}

... WHICH results in this error...

In file included from C:\Users\user\AppData\Local\Temp\.arduinoIDE-unsaved202428-14972-1bonrpg.txde\sketch_mar8a\sketch_mar8a.ino:10:0:
c:\Users\user\OneDrive\Documents\Arduino\sketchbook\libraries\ServoEasing\src/ServoEasing.h:886:2: warning: #warning You probably must change the line #include "ServoEasing.h" to #include "ServoEasing.hpp" in your ino file or define SUPPRESS_HPP_WARNING before the include to suppress this warning. [-Wcpp]
 #warning You probably must change the line #include "ServoEasing.h" to #include "ServoEasing.hpp" in your ino file or define SUPPRESS_HPP_WARNING before the include to suppress this warning.
  ^~~~~~~
C:\Users\user\AppData\Local\Temp\.arduinoIDE-unsaved202428-14972-1bonrpg.txde\sketch_mar8a\sketch_mar8a.ino: In function 'void setup()':
C:\Users\user\AppData\Local\Temp\.arduinoIDE-unsaved202428-14972-1bonrpg.txde\sketch_mar8a\sketch_mar8a.ino:24:6: error: redefinition of 'void setup()'
 void setup() {
      ^~~~~
C:\Users\user\AppData\Local\Temp\.arduinoIDE-unsaved202428-14972-1bonrpg.txde\sketch_mar8a\sketch_mar8a.ino:1:6: note: 'void setup()' previously defined here
 void setup() {
      ^~~~~
C:\Users\user\AppData\Local\Temp\.arduinoIDE-unsaved202428-14972-1bonrpg.txde\sketch_mar8a\sketch_mar8a.ino: In function 'void loop()':
C:\Users\user\AppData\Local\Temp\.arduinoIDE-unsaved202428-14972-1bonrpg.txde\sketch_mar8a\sketch_mar8a.ino:34:6: error: redefinition of 'void loop()'
 void loop() {
      ^~~~
C:\Users\user\AppData\Local\Temp\.arduinoIDE-unsaved202428-14972-1bonrpg.txde\sketch_mar8a\sketch_mar8a.ino:6:6: note: 'void loop()' previously defined here
 void loop() {
      ^~~~

exit status 1

Compilation error: redefinition of 'void setup()'

Then you copied your original sketch from the source and pasted it here... when you should have been using the "sketch" in your IDE.

Tell us how your mask is doing after you make the changes.

1 Like

Thanks for your help! I managed to compile, now I need to understand the reason of the erratic behaviour. :wink:

Show your new sketch, and also show the result of the compile. This will help understanding what you see.

5 posts were split to a new topic: Expected declaration before '}' token

Your immediate problem is that you need another closing brace at the end. One of these }