custom main programming question

Would you like to help?
Share your walkthrough tutorial with others

Posts: 247
Joined: Thu Sep 01, 2011 8:44 pm
PostPosted: Fri Jan 06, 2012 8:04 pm
Hey Curt (or Roberto)

I have created my own screen by cutting and pasting alot, but I am getting the hang of coding and want to understand more so I can do more on my own is something I don't the code below, what do the lines "byte x=6" and "byte y=2" and "byte t" mean? They are used later adding numbers to define spots on the X/Y axis, right? but what does it do that just putting in a number value doesn't do? I feel like this is a newb question, and that it may be an obvious coding answer, but I can't figure it out on my own...thanks in advance...

Code: Select all

void DrawCustomMain()
byte x = 6;
byte y = 2;
byte t;
ReefAngel.LCD.DrawLargeText(COLOR_DARKTURQUOISE, COLOR_WHITE, 6, 2, [color=#006699]"Rob's ReefAngel"[/color]);
ReefAngel.LCD.DrawDate(6, 118);
ReefAngel.LCD.Clear(COLOR_MAROON, 1, 17, 132, 17);
ReefAngel.LCD.Clear(COLOR_MAROON, 1, 115, 132, 115);
ReefAngel.LCD.Clear(COLOR_MAROON, 1, 90, 132, 90);
x = 6;
ReefAngel.LCD.DrawText(COLOR_BLUE, COLOR_WHITE, x, y+6, [color=#006699]"Display Tank     PH"[/color]);
[color=#CC6600]char[/color] text[7];
ConvertNumToString(text, ReefAngel.Params.PH, 100);
ReefAngel.LCD.Clear(DefaultBGColor, x+8, y+65, x+65, y+16);
ReefAngel.LCD.DrawLargeText(PHColor, DefaultBGColor, x+90, y+18, text);

ConvertNumToString(text, ReefAngel.Params.Temp1, 10);
x = 10;
ReefAngel.LCD.DrawHugeNumbers(T1TempColor, DefaultBGColor, x, y, text);
x += (16*4) + 8;
ReefAngel.LCD.DrawText(COLOR_BLUE, COLOR_WHITE,8,y+25,[color=#006699]"ROOM:"[/color]);
ReefAngel.LCD.Clear(COLOR_CRIMSON, 8, y+33, 32, y+33);
ReefAngel.LCD.DrawSingleMonitor(ReefAngel.Params.Temp2, T2TempColor, 
9, y+36, 10);
ReefAngel.LCD.DrawText(COLOR_BLUE, COLOR_WHITE,x+8,y+25,[color=#006699]"FRAG:"[/color]);
ReefAngel.LCD.Clear(COLOR_CRIMSON, x+8, y+33, x+32, y+33);
ReefAngel.LCD.DrawSingleMonitor(ReefAngel.Params.Temp3, T3TempColor, 
x+9, y+36, 10);

[color=#CC6600]byte[/color] TempRelay = ReefAngel.Relay.RelayData;
TempRelay &= ReefAngel.Relay.RelayMaskOff;
TempRelay |= ReefAngel.Relay.RelayMaskOn;
ReefAngel.LCD.DrawOutletBox(12, 96, TempRelay);


[color=#CC6600]void[/color] DrawCustomGraph()

User avatar
Posts: 2849
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
PostPosted: Fri Jan 06, 2012 8:19 pm
Those lines are variable declarations and initializations. You must declare a variable before you can use it, plus it must contain a value before use or else you will get erroneous data which can lead to undesired results.

Yes, they are used later define spots on the X/Y axis. You are correct, you could just as easily use regular values / numbers in their place. The reason why they are used is for several reasons.

1. It makes positioning things relative for each other and changing the general layout can be simpler to move everything all at once instead of manually changing every value. If you look at the code, you will see several += (which means add the value to the right of the equals to the value stored in the variable) in the code. With some of the things that are on the same line, it's much easier to have everything shift based on a single change instead of you having to count things manually and "guess" what the right position is. Computing ensures consistent results.
2. We perform several computations on the values based on other things. Performing the calculations and storing them in the variable makes the code easier to read and also ensures the compiler (the program that reads the code you write and converts it into machine language) processes the code the way you want it to.
3. Simplicity. Plain and simple when you code, you try to make things as simple as you can. The more complicated the code is, the harder it is to debug and maintain. If you keep it simple and easy to read, it makes much more sense for people looking at. This is combining points 1 & 2.

Looking at the code you copied, I should have used the X & Y in the first drawtext line in place of the 6 & 2. It was just a simple error that I made when writing the manual.

You are correct, a lot of this is basic and simple coding strategies. But, if you do not know, it's a completely legitimate question to ask.

Hopefully that answers your question and makes sense for you. If not, feel free to ask more questions.

Posts: 247
Joined: Thu Sep 01, 2011 8:44 pm
PostPosted: Fri Jan 06, 2012 11:45 pm
Thanks for taking the time to give such an in depth response...this makes alot of sense, I get it now...this gives a consistency and takes away the "brute force" means of finding positions by just counting pixels and hoping for the best....I am looking to tweak my display to line things up differently, this will make it much easier...

Return to Tutorials

Who is online

Users browsing this forum: No registered users and 1 guest