What do you think?

what do you think about my program ?

I had a servo motor, an ultrasonic sensor, 2 pwm motors and an arduino mega 2560, board...

the servo moves his head (the ultrasonic sensor) and the pwm motors are his wheel...

I accept all kind of critics or suggestions....

MODIFIED ... CHECK LAST COMMENT !!

int LED1 = 13;                                                    //LED1 --meghatarozza a LED1 labat
int LED2 = 13;                                                    //LED2 --meghatarozza a LED2 labat

Why do you have two variables that appear to be pin number holders holding the same value?

the servo moves his head
Servo myservo;                                                    //SZPEAKER ---nem toom mi az de ott kell legyen :D---

What does the comment have to do with the code? If the servo moves the head, don't you think a name like headMover makes more sense than myservo? Who else's servo would it be?

int c = 261;                                                      //SZPEAKER --meghatarozza a c valtozot
int d = 294;                                                      //SZPEAKER --meghatarozza a d valtozot
int e = 329;                                                      //SZPEAKER --meghatarozza a e valtozot
int f = 349;                                                      //SZPEAKER --meghatarozza a f valtozot
int g = 391;                                                      //SZPEAKER --meghatarozza a g valtozot
int gS = 415;                                                     //SZPEAKER --meghatarozza a gS valtozot
int a = 440;                                                      //SZPEAKER --meghatarozza a a valtozot
int aS = 455;                                                     //SZPEAKER --meghatarozza a aS valtozot
int b = 466;                                                      //SZPEAKER --meghatarozza a b valtozot
int cH = 523;                                                     //SZPEAKER --meghatarozza a cH valtozot
int cSH = 554;                                                    //SZPEAKER --meghatarozza a cSH valtozot
int dH = 587;                                                     //SZPEAKER --meghatarozza a dH valtozot
int dSH = 622;                                                    //SZPEAKER --meghatarozza a dSH valtozot
int eH = 659;                                                     //SZPEAKER --meghatarozza a eH valtozot
int fH = 698;                                                     //SZPEAKER --meghatarozza a fH valtozot
int fSH = 740;                                                    //SZPEAKER --meghatarozza a fSH valtozot
int gH = 784;                                                     //SZPEAKER --meghatarozza a gH valtozot
int gSH = 830;                                                    //SZPEAKER --meghatarozza a gSH valtozot
int aH = 880;                                                     //SZPEAKER --meghatarozza a aH valtozot
int DO = 261;                                                     //SZPEAKER --meghatarozza a DO valtozot
int RE = 294;                                                     //SZPEAKER --meghatarozza a RE valtozot
int MI = 329;                                                     //SZPEAKER --meghatarozza a MI valtozot
int FA = 349;                                                     //SZPEAKER --meghatarozza a FA valtozot
int SO = 391;                                                     //SZPEAKER --meghatarozza a SO valtozot
int La = 440;                                                     //SZPEAKER --meghatarozza a La valtozot
int SI = 466;                                                     //SZPEAKER --meghatarozza a SI valtozot

Good thing you've learned about arrays.

 void loop()                                                    
 //Elkezdi azt a reszet a programnak amit mindig ujra kezd a robot mukodese kozben 
{                                                                 
    if (Serial.available())
 {
    char ch = Serial.read();

Lovely indenting. NOT!

      goto detect;

30 years developing C and C++ code, and I've never needed to wuss out with a goto.

  while (Talalkozas == 8)                                             
  {                Serial.print("Talalkozas = ");Serial.println(Talalkozas);                                             
   StarWars();     Serial.println("StarWars Indul..");
   Talalkozas++;         Serial.print("Talalkozas = ");Serial.println(Talalkozas);
                                                                  
  }

A while loop that is only going to iterate once at most is stupid.

  ALLFORWARD(255-Faradtsag);

By convention, all capital letter names are reserved for constants. A function is hardly a constant.

I quit reading when I saw where the detect label was. Ctrl-A, Ctrl-X, and start over WITHOUT the goto crap.

I'm too lazy to read 42k of code.

If something isn't working and you can identify the 10 or 20 lines where the problem is, or better still write a short complete sketch that illustrates the problem I will try to help.

...R

For the last post... I don t have any problem i need only suggestions

And for Paul .. Thx for help.. otherwise 1.LED1 and LED2 now are the same becouse i have only 1 led for now but i will have more 2. I think goto makes the program shorter 3. void loop() //Elkezdi azt a reszet a programnak amit mindig ujra kezd a robot mukodese kozben { if (Serial.available()) { char ch = Serial.read();

---- i m sory but i didnt understand the problem whit that ... 4. ALLFORWARD(255-Faradtsag); Faradtsag is the Fatigue... 5. I quit reading when I saw where the detect label was. Ctrl-A, Ctrl-X, and start over WITHOUT the goto crap.-- i m srry i m not english and i don t understand

i m sory but i didnt understand the problem whit that

Well, come back when you've evolved into a life-form which does.

How many more times are you going to start new posts on the same topic and code? (Hint: it's a very small number)

i m srry i m not english

Neither is PaulS :D

AWOL:

i m sory but i didnt understand the problem whit that

Well, come back when you've evolved into a life-form which does.

How many more times are you going to start new posts on the same topic and code? (Hint: it's a very small number)

i m srry i m not english

Neither is PaulS :D

I m only a 6-th class romainian boy ... i m only 12 years old and i have a little hobby .... why should u blame me if i don t understand something ?? otherweise goto makes the program shorter.. there is a reason why the employers have created it ill sayd that i will accept critics but i can t guarantee that i can fix the problems... I THANK VERY MUCH for Paul that he helped me and he didn t blame me like you...

      goto detect;

"""""30 years developing C and C++ code, and I've never needed to wuss out with a goto."""""

I understanded (whit Google Translate) and resolved all you sayd but i don t know how to do the same thing whitout using goto.. plz help me...you surely can..

And you sayd """" i stopped reading """"... plz read it to the end and say me the other problems you found..

otherweise goto makes the program shorter.

With or without "goto", I can write very short code that is both efficient, clever and . . . completely unreadable and unmaintainable

i will accept critics but i can t guarantee that i can fix the problems

. So, accept this criticism (note, not "blame") - do your very best not to use "goto". I didn't start programming until I was 16, when I was taught BASIC, and back then (in the late Mesolithic), all we had was "goto". It took a long time to get out of the habit, because our teacher didn't know any better.

PaulS:

i created a new version… I deleted void pause(dur) I placed voids in logical order i deleted some of comments i used auto format and i reformatted manualy too… here s the new code:

What do you think??

PROGRAM.ino (39.6 KB)

i used auto format and i reformatted manualy too…What do you think??

void setup()                                                                     
 //Elkezdi azt a reszet a programnak amit csak a program elejen csinal meg 
{                 
                   Serial.begin(9600);                                                            
             Serial.println("AFRP1 Elindult!");
                   Serial.println("");
                          
                           
 pinMode(LED1, OUTPUT);   //LED1  output ba rakja

I think you should have let Tools + Auto Format do its thing, and not f**ked up what it did.

You did NOT get rid of the gotos. You do NOT need to use goto. Get rid of them.

You will NOT get a passing grade from me until you do.

PaulS: I think you should have let Tools + Auto Format do its thing, and not f**ked up what it did.

You did NOT get rid of the gotos. You do NOT need to use goto. Get rid of them.

You will NOT get a passing grade from me until you do.

I delete goto detect; but i can t delete goto here; because its very usefull and i don t know how to resolve whitout this command.. if you help me i delete that too... at about auto format .. i cant let it alone because it is worse but i will resolve that thing if you don t like it

this is it… i only deleted the if and repositioned the start of the loop… so its not a big thing…

PROGRAM.ino (39.5 KB)

lori3: I delete goto detect; but i can t delete goto here; because its very usefull and i don t know how to resolve whitout this command.. if you help me i delete that too... at about auto format .. i cant let it alone because it is worse but i will resolve that thing if you don t like it

I want to say : is there any way to do the same thing whitout recopyng the part of the program and whitout createing a 100KB program??

but i can t delete goto here; because its very usefull and i don t know how to resolve whitout this command..

The two parts of this statement are not compatible. The goto statement is very useful, but not to you. There is NO reason for you to be writing code that uses goto.

The fact that you don't know how to write code that doesn't use goto means that you need to learn more about C/C++ before tackling a project of this complexity.

You need to create functions that do a lot of the stuff you are doing. Functions are a good thing because you can't goto from one function to another, so you are forced to learn how to encapsulate code in functions correctly.

OK.. I have only 2 more questions... 1.what version in c++ i should read about ? because i have an old All about c/c++ boob 10% readed but it is very different , its not like arduino programming.. 2.I don t have any more ideas about what can the robot do... You have any more ideas for it ?

Download the IDE 1.5.7, then you can activate C++11, which will be active in 1.5.8 and above.

C++11 is mostly additions to C++98, there are only a handful of rules/keywords/features that have changed significantly ( auto for instance ). So just search for any C++ info, if you need C++11 its there for you to use.

Question 2, haven't read much of your topic, however a robot always needs lasers.

is there any way to do the same thing [as the goto]

How about:

  case 's':  //s(stop) esetben ((:))
    while ( turndirection == 's') {

      Serial.println("Hatra tolatok majdszetnezek");
      ALLBACKWARD(200-Faradtsag);
      delay(700);
      ALLBACKWARD(200-Faradtsag);
      delay(700);
      ALLBRAKE(30);
      delay(20);

      char turndirection = scan();
      switch (turndirection)
      {

      case 'l':   //l(left) esetben ((:))

        Serial.println("Balra megyek");
        ALLLEFT(250-Faradtsag);
        delay(670);
        ALLBRAKE(30);
        break;

      case 'r':  //r(right) esetben ((:))

        Serial.println("Jobbra megyek");
        ALLRIGHT(250-Faradtsag);
        delay(670);
        ALLBRAKE(30);
        break;

      case 's':   //s(stop) esetben ((:))
        break;   // stay stopped by looping.
      } // inner switch
    } // while "stopped"

I don't quite understand what your code is doing (ALLBACKWARD for 700 ms doesn't seem like "stopped."), but I'm pretty sure that the program logic here accomplishes the same thing you did with your goto...

what version in c++ i should read about ?

C++ 98. It's the most commonly used software in the world.

i have an old All about c/c++ boob

Really? I find that rather ironic. 8)

but it is very different , its not like arduino programming

Yes, it is. You simply haven't recognized the similarities yet, or didn't understand the material.

c/c++ boob

Is that slightly smaller than a D?

Not so much as an supportive comment on the coding style, but more so on the way lori3 handles this :D

12 years old, doing exactly what some of you asses accuse lori3 of needing to do .... learning and getting help, which is exactly what lori3 does in this thread.

Props little one, your doing well and making progress, coming here and asking for help and judgement on your code is one of the foremost things to do next to looking it up in a book or on the web; seeking help from experienced programmers :)

I would have totally flipped from some of the replies you got :sweat_smile:

pokes AWOL ya crude bastard ]:)

10 print "gw basic is for oldies"
20 goto 10

:roll_eyes:

I thought the world of gosub at some point in time :disappointed_relieved: