Why is it that the code I have posted appears jumbled up but looks normal when inserted between brackets?
-
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-punctisOct 6, 2018 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?– robbieOct 6, 2018 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 ModOct 7, 2018 at 20:33
-
Thanks for all the help, I very much appreciate it! :)– robbieOct 8, 2018 at 10:59
1 Answer
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.
-
-
No problem - I know this from having tried do by hand, what the site could do for me.– JRobertOct 6, 2018 at 11:15