@chris,
A bit of additional information if you have interest why what you had was not working.
The C syntax you have used, while valid, I'm pretty sure is not what you are intending.
Lets look at several of the lines 1 by 1.
if ((byte)accx < 100 > 130) // <== Heres the problem
GLCD.DrawLine(0, 32, 64, 0); // --
The compiler will toss this code completely away.
The reason is that the expression inside the if statement will always evaluate to 0/false.
It will first look accx < 100 part of the expression.
That will evaluate to 0 or 1 depending on the value of accx if it is less than 100.
But it doesn't matter because both 0 and 1 are never greater than 130
so the overall expression evaluates to 0/false. Because of this
the compiler will toss the code.
I'm not exactly sure what you wanted.
Were you wanting to check for either less than 100 or greater than 130?
(less than 100 *and* greater than 130 doesn't make sense)
If so then to do that in C code you would use:
if((accx < 100) || (accx > 130))
GLCD.DrawLine(0, 32, 64, 0);
Or if accx were greater than 100 and less than 130?
If so you would use:
if((accx > 100) && (accx < 130))
GLCD.DrawLine(0, 32, 64, 0);
The next two if statements have a very common error.
if ((byte)accx > 99 < 73); // ---
GLCD.DrawLine(0, 63, 127, 0); // ----
Note the semicolon on the if? That should not be there.
The result of that is that the if statement is thrown away because the statement following the if is a null statement (the semicolon) and so the statement below the if is outside the if and so it is always executed.
But again, the if syntax needs fixing as well similar to the first if statement.
Those fixes will fix the drawing, or you can use Michael's nested if statement to support different ranges for drawing lines, but in the larger picture, you may eventually need some additional logic to erase what you have drawn. Otherwise as you move the nunchuk around, all the lines will eventually be drawn.
You can either do this by clearing the entire display each pass through the
loop or you can draw the proper line in black or white (which will erase it) depending if you want the line or not.
for example:
if((accx > 100) && (accx < 130))
GLCD.DrawLine(0, 32, 64, 0, BLACK);
else
GLCD.DrawLine(0, 32, 64, 0, WHITE);
But it gets complicated when you have more than one line to ensure that the multiple line erases don't erase pixels in the the new line you want or pixels in your horizontal line.
The easiest thing for now, is to erase the display when you do an update inside your loop() function, then redraw your horizontal line, and then use Michael's nested if example to draw the line you want based on your nunchuk position.
But in using Michael's nested if example, I would HIGHLY recommend
the use of curly braces . I always use curly braces on anything more than a single line simple if statement. It helps preventing unintended accidental logic or syntax errors.
Which BTW, there is an error in the example:
The first part of the if is incorrect. It should be:
if ( accx > 186)
; // do nothing for values greater than 186
else if ( accx > 130)
OR
if ( accx > 186)
{
// for values greater than 186
GLCD.DrawLine(0, 63, 127, 0);
}
else if ( accx > 130)
--- bill