Guides on posting code in your posts.


  • Without your code, we cannot provide any answers about your code, other than the most vague and probably unhelpful of answers. One of the frustrating things about writing code is that a mistake in one place can produce an error in what seems like a completely different, unrelated place. This is a nightmare if you are new to writing code, but often easy to spot for anyone who is experienced in looking for such problems. It is for this reason we want all your code, not just the bit with the error or the bit you think is causing the problem.

    Code should be in code tags, these are the {;} in the tool bar above where you edit your post, and correctly formatted, like this:

    void loop()
    {
      for (int i = 0; i <= 180; i++)
      {
        myservo.write(i); //write the i angle to the servo
        delay(15); //delay 15ms
      }
      for (int i = 180; i >= 0; i--)
      {
        myservo.write(i); //write the i angle to the servo
        delay(15); //delay 15ms
      }
    }
    

    If you don't use code tags then it may end up like this:

     

    void loop()
    {
    for (int i = 0; i <= 180; i++)
    {
    myservo.write(i); //write the i angle to the servo
    delay(15); //delay 15ms
    }
    for (int i = 180; i >= 0; i--)
    {
    myservo.write(i); //write the i angle to the servo
    delay(15); //delay 15ms
    }
    }

     

    Common mistakes with code and posting code

    Posting a screenshot of code or error messages. A screenshot is useless, with a screenshot it is impossible for us to paste the code and test it. Please post your code and error messages, not an image of them.

    Only posting the part of the code you think has the problem. Often code problems are not in the place they might obviously seem to be, often a mistake in one place shows up as a problem elsewhere. The only way to see this is to see all the code. Also be aware that some mistakes cause a cascade of multiple errors, if this happens deal with the first one and see if the other disappear.

     

    Error messages

    When you compile your code, it's really common to encounter certain problems with the code and generate error messages to indicate any problems it finds. If this happens then we need to see the error messages as well as the complete code, as the error messages offer clues to what the problem is, often the error messages indicate exactly what the problem is if you understand how to read them. 

     



This topic is locked!