Why is it that the code I have posted appears jumbled up but looks normal when inserted between brackets?

migrated from arduino.stackexchange.com Oct 6 '18 at 7:25

This question came from our site for developers of open-source hardware and software that is compatible with Arduino.

  • You need at least 4 spaces (not tabs!) to precede every single line. Additional spaces will indent those lines. arduino.stackexchange.com/editing-help#code – ex-punctis Oct 6 '18 at 0:53
  • "enter code here" is where I pasted my original code and it was fine. In subsequent edits (re-pasting) has left a mess. Before saving the edit, the code looks fine whilst scrolling but appears below very jumbled and when saved shows as jumbled. Must spaces be added manually to each line of code? – robbie Oct 6 '18 at 1:15
  • Select all the code and then hit Ctrl+K (think of K as in Kode). (Ctrl+C has already been used for "Copy"). That puts 4 spaces before each line. If you do it a second time it takes the 4 spaces away. – Nick Gammon Oct 7 '18 at 20:33
  • Thanks for all the help, I very much appreciate it! :) – robbie Oct 8 '18 at 10:59
  • Format your code in the Arduino IDE (or in whatever code-entry editor you are using). In the Arduino IDE, it's the 'Tools | Autoformat' menu item.

  • Copy/paste your code into Arduino Stack Exchange's question or answer text-entry box. (If you're trying to show code in a comment, forget about formatting. Comment boxes strip all the indenting and newlines out of it. The best you can do in a comment is enclose it in back-ticks: `` to give it a gray background).

  • Select the entire block of code and click the '{}' symbol in the text-entry box's header. That will indent your code so the site will recognize it as code and keep its formatting.

  • Sorry for my noob issues, I have it now! – robbie Oct 6 '18 at 7:37
  • No problem - I know this from having tried do by hand, what the site could do for me. – JRobert Oct 6 '18 at 11:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .