How to Add Code to Your Post

This is a forum where we discuss using microcontrollers and microcomputers, so it is very useful to be able to put code samples into your post.

Although you can add code to your post as an attachment, this is usually not the best idea. Most people won’t want to download the attachment and open it, especially if they are on mobile devices, so you’ll get fewer (if any) responses.

It is much better to put the code directly into your post. But don’t just paste it into your post unformatted, it really looks ugly and is often just unreadable.

Instead, follow these simple instructions to properly format your code:

Formatting your code

The forum has a built-in formatting function to format code so that it is much more readable. It works for all code languages, including C++ and Python.

And it’s really very easy to use:

Step 1 – Copy the code sample from your computers editor, it can be any text editor or IDE.

Step 2 – Paste it into your post, at the point you want the sample to occur

Step 3 – To make things easier add a couple of line feeds after you paste it.

Step 4 – Highlight the code in your post.

Step 5 – Click the Code button (the one that looks like “<>”) on the post editor toolbar.

This will change the font you see in the editor. And if you now click the Preview link to look at your post you will see that it is nicely formatted.

One other hint – if your code is very long try and just post the section you are having problems with. While there is no actual limit to the amount of code you can post, long code samples can be hard for readers to get through, especially if it is only one section you are interested in highlighting.

And, of course, you can also break your code down into sections and post them individually, so you can highlight the section of interest while still posting all of the code.