body, html {font-family: 'Open Sans', sans-serif;} #nav a, #nav span.in{font-family: 'Open Sans', sans-serif;} #title #tagline {font-family: 'Open Sans', sans-serif;} #main .gridItem h3 {font-family: 'Open Sans', sans-serif;}

Working with Tabs

Drymat


I started to report on this topic inside the entry of the 15th JC: Wire Loop Game. I now decided to talk here about my findings and so moved that part to here…


8/03/2016 Started Working with Tabs

When I tried to adapt the Tetris cache I became aware that this sketch was split to various tabs. I thought about and tested a little bit. The result is, that this is my first sketch, I splitted also. The main program (first tab) is containing all the stuff which is special for this sketch. The second one is containing all my subroutines I’m using in most or all of my programs. 

What’s the advantage to do so? There’re at least 2:

  1. Your main program will become much shorter because it’s only containing the part, you’re really working on. And that’s the case not only for the program itself but also for the head, where you’re defining all the variables. As you can see, all variables only used by the subprogrames are now declared on that tab. This is making the program, you’re just working on, much more handy.
  2. I think, the second advantage is much more important. Let’s assume you’re updating a subprogram. I did it with my LCDWrite. The first one was just working, the second one was using a variable which was used when calling the subprogram to manage different delays when the text is shown and the third one was able to manage 16x2 and 20x4 LCDs. When there was a new version, I had to copy the new version into all the sketches, I wanted to use that new version. In future I’ll update the file Z_Common_Subs.ino only once and after that just copy that file into all the folders of the sketches, I want to use that update.


8/05/2016 Next Step

I reworked some existing sketches with the pribciple of tabs. Yes, it’s really great. But my idea to put all common subroutines into ones sketch wasn’t. First problem is that you have define in the main sketch some variables of the subroutines you’ll never use. And the second one is that the compiler will compile all, even the unused ones. And that’s a real mess, because wer’re already struggeling with memory sometimes. So I separated all common subroutines to single files (The’re ready for download on the sketch page): 

The sketch with the same name as the folder is seen by the IDE as the main sketch. All other sketches as subroutines…


8/09/2016 Definition of Variables - Understood!

During some free time (unfortunately actually very limited) I continued to work on the sketch with the Tetris Cache. I struggled a lot with the definition of variables used on different tabs. At the end I’ve understood and here’s the result:

Tabs 1

The „main program"


Tabs 2

The „sub program"

This is for sure a very small program. But what it shows? The variable variable_sharded is set in the main program and used in the sub program to define what’s written to the serial monitor. The variable is declared at the beginning of the main program as usual. But it’s also declared inside the sub program. But in a different way.

  1. „extern“ is in front of the definition. This is telling the compiler that he doesn’t need any additional memory for this variable, because it’s already defined (and the space reserved) somewhere else.
  2. You need only to declare at but you can’t assign a value to it. (So external int variable_shared = 0; would cause a compiling error).


I think, now I’m a little bit better prepared to continue working on the Tetris cache...





©  Olaf Goette 2008 - 2018