Need help for a new project program

The project it self is done, but I don't now what is wrong with the program.
Link:

#include <Servo.h>

int Main;
int motorB;
int motorP;

Servo motor1;
Servo motor2;
Servo motor3;
Servo motor4;
Servo motor5;

int alt;

//botao
int buto1;
int buto2;
int buto3;
int buto4;
int buto5;

//potenciometro
int pote1 = 0;
int pote2 = 0;
int pote3 = 0;
int pote4 = 0;
int pote5 = 0;

void setup() {
pinMode(7, INPUT);

motor1.attach(2);
motor2.attach(3);
motor3.attach(4);
motor4.attach(5);
motor5.attach(6);

pinMode(8, INPUT);
pinMode(9, INPUT);
pinMode(10, INPUT);
pinMode(11, INPUT);
pinMode(12, INPUT);
}

void loop() {
goto Main;
Main:
alt = digitalRead(7);
if (alt = HIGH) {
goto motorB;
}
if (alt = LOW) {
goto motorP;
}
goto Main;

motorB:
buto1 = digitalRead(8);
if (buto1 == LOW) {
motor1.write(0);
}
else {
motor1.write(180);
}

   buto2 = digitalRead(9);  
   if (buto2 == LOW) {
     motor2.write(0);
   }
   else {
     motor2.write(180);
   }

   buto3 = digitalRead(10);  
   if (buto3 == LOW) {
     motor3.write(0);
   }
   else {
     motor3.write(180);  
   }

   buto4 = digitalRead(11);  
   if (buto4 == LOW) {
     motor4.write(0);
   } 
   else {
     motor4.write(180);  
   }

   buto5 = digitalRead(12);  
   if (buto5 == LOW) {
     motor5.write(0);
   }
   else {
     motor5.write(180);    
   }

if (alt = HIGH) {
goto motorB;
}
else {
goto Main;
}

motorP:
pote1 = analogRead(A1);
int pos1 = map(pote1, 0, 1023, 0 , 180);
motor1.write(pos1);

   pote2 = analogRead(A2);
   int pos2 = map(pote2, 0, 1023, 0 , 180);
     motor2.write(pos2);

   pote3 = analogRead(A3);
   int pos3 = map(pote3, 0, 1023, 0 , 180);
     motor3.write(pos3);

   pote4 = analogRead(A4);
   int pos4 = map(pote4, 0, 1023, 0 , 180);
     motor4.write(pos4);

   pote5 = analogRead(A5);
   int pos5 = map(pote5, 0, 1023, 0 , 180);
     motor5.write(pos5);  

if (alt = LOW) {
goto motorP;
}
else {
goto Main;
}
}

I haven't had a good look, but lines like that should be == not =.

And all those gotos are going to make it very difficult to debug for someone like me who hasn't used goto since Fortran 45 years ago, sorry.

This is the first thing that is wrong. Goto is not the way to go.
With a little help you could switch this over to a properly structured program.

You can create pretty much any program using:

  • Iterative logic, those are your for loops and while loops to do something over and over but only in one place, like turning on a sequence of lights
  • Branching logic, those are your if/else and switch to decide which path your program takes
  • Functional logic, those are subroutines, functions that you create to do the same thing in different parts of your program without repeating code

I bet you a glazed donut that if we get your code goto free you'll understand it better and your problem will either be fixed or be easier to spot and fix.

Are you up for the challenge?

Hello
Describe your project in simple words and this very simple.

It's in the wrong forum section, and missing code tags.

You could ask a moderator to fix the first for you.

Then there's the gotos and the comparisons.

Probably some of the variables don't need global scope.

Named pins would help.

A simple bionic hand.

Sorry, it's my first time using this forum. I don't really know how to use C++.

Hello
Which functions have the used buttons and pots and what is the functional relation between both?
Sorry, my crystal ball is in the dishwasher.

both moves the same engines, in analog or digital form, depending on switch position.

Hello
In this case design a common data structure, so called object containing all related information pro "finger" and use a function/methode to work on this data structure. Shortly called: Use the C++ programming languages to design a proper and smart sketch.
Have a nice day and enjoy coding in C++.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.