OK,so this is my first program written via the Tinkercad utility. I have saved the program as a text file, and it equates to about 22K.

My simple question is, when uploaded / compiled to the actual board, is the size increased or decreased? I plan to use the Nano (32K) If it shrinks or stays roughly the same, I should be OK. However,if it 'bloats' due to extra C code ...

** As someone used to working with sub routines, arrays and variables, found it a bit of a hassle that everything has to be in one loop, only conditional statement breaking the flow - leastin TinkerCAD. And when you want to control 8 LED outputs, having to switch each one on and off via a digital write line. For example, the four output lines below:


... needs 32 digital write commands !! (And whilst the above is 4 lines, there are nearer 150 similar lines in final code, hence it's size)

The way I wrote it using ths above utility was something like:

for(counter=0; counter<4; counter){
if (counter==0){
    digitalWrite(2, HIGH);
    digitalWrite(3, HIGH);
    digitalWrite(4, LOW);
    digitalWrite(5, LOW);
    digitalWrite(6, HIGH);
    digitalWrite(7, HIGH);
    digitalWrite(8, LOW);
    digitalWrite(9, LOW);
if (counter==1){
    digitalWrite(2, LOW);
    digitalWrite(3, HIGH);
    digitalWrite(4, HIGH);
    digitalWrite(5, LOW);
    digitalWrite(6, LOW);
    digitalWrite(7, HIGH);
    digitalWrite(8, HIGH);
    digitalWrite(9, LOW);
  • Though I don't know if this works in Tinkercad, but you can use direct port manipulations to do this. Then you are able to write a complete port (8 outputs) in one statement (actually 1 atomic operation). Have you tried this?
    – chrisl
    Jun 13 '19 at 13:13
  • 1
    and why do you use TinkerCAD if you can code? use Eclipse with Sloeber plugin. or at least the Arduino IDE
    – Juraj
    Jun 13 '19 at 13:14
  • "direct port" ... "1 atomic operation".Sorry, only been coding for four days,so that's gone right overmy head ! WHy use Tinkercad if you can code? Well, I know PERL,HTMLand Javascript ... but Arduino is all a new game for me Jun 14 '19 at 17:30

The size of the text file and the size of your compiled code are impossible to relate. The compiled size purely depends on what your code consists of, not the size.

To find out how much room your code will take on the chip you need to compile it. The IDE will then tell you how much flash and RAM it takes.

For example:

Sketch uses 3730 bytes (13%) of program storage space. Maximum is 28672 bytes.
Global variables use 157 bytes (6%) of dynamic memory, leaving 2403 bytes for local variables. Maximum is 2560 bytes.
  • You can compile the code without even having the board. So you could even compare different boards, before buying. (Though it shouldn't be that different between the nano and the uno)
    – Gerben
    Jun 13 '19 at 15:05
  • Thanks for the feedback Majenko. You've sort of said what I thought might happen, that there are certain 'housekeeping' codes that also have to go into the storage space in order to be able to 'read' the text (or ino?) file. The only way to know for sure will be to run it through the IDE,but not save it to board, (if that's even poss: Still very much a noob!) Jun 14 '19 at 17:41
  • @Cristofayre In the IDE you can compile the code (called "verify" in the IDE IIRC) which creates a file that can be installed into a board or a later date. Or you can compile and upload in one go. You can just hit the compile (or is it verify?) button and it will convert the C code into machine language for running on the board (the board does not run C) and it tells you how big the result is.
    – Majenko
    Jun 14 '19 at 19:00
  • Thanks Majenko. I will look into that. I've also just signed up for an online (FREE) course, so we'll see what I can learn from their coding. (Sorry, I can't 'upvote' your answer at this stage) Jun 16 '19 at 15:05

Does counter increase somewhere? As written, it would always be 0, yes?

I would use

for(counter=0; counter<4; counter = counter +1){ // or counter++

You could store your 8 bits in an array

byte ledArray[] = {
0b11001100, // or hex format, 0xCC
0b01100110, // 0x66
0b00110011, // 0x33
0b10011001, // 0x99

Then use a function call (subroutine by another name) to manipulate the outputs.

  • Apologies. You're right, I missed the "counter ++" off the end of the loop. I think what you suggest of "byte ledArray" enters the realm of manual coding, (which, now I know it can be done, might look further) But Tinkercad uses Codeblocks,so the code they build is 'basic'. (And if you switch to manually editing code...you lose all the previous blocks set up!) Jun 14 '19 at 17:35
  • What I like about TinkerCad is that it shows the Arduino PCB, and you can add virtual resistors and LED's etc to it, and then you get a visual indication of what the code blocks will do. (But even to add a library, you have to edit manually; no blocks to help.That will be OK once I start to know more of whatI'm doing !) Jun 14 '19 at 17:37
  • Not sure of the correct way to do this on the forum, but I have "devised" a possible solution. Since this is my first atttempt at manual coding - jumping in at the deep end - I have posted it as another question, and wondered if those more knowledgable to give it the once over ... especially as it involves arrays, binary 'strings', and reading individual bits ! Jun 18 '19 at 8:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.