m & m
I have tested and edited my code to get some good results, but...
I did try the long command and it was returning me negative numbers all the time. Could it be the printDouble function i am using or just me as usuall

.
One code below that can be used with serial.print and one with the KS0108 library.
This one will run to 0.3 and then just jump to -1
int X = 5;
//////////////////////////////////////////////////////////////////////////
void printDouble( double val, unsigned int precision){
Serial.print (int(val)); //prints the int part
Serial.print("."); // print the decimal point
unsigned int frac;
if(val >= 0)
frac = (val - int(val)) * precision;
else
frac = (int(val)- val ) * precision;
int frac1 = frac;
while( frac1 /= 10 )
precision /= 10;
precision /= 10;
while( precision /= 10)
Serial.print("0");
Serial.println(frac,DEC) ;
}
//////////////////////////////////////////////////////////////////////////
void setup(){
Serial.begin(9600);
}
void loop(){
float GX = analogRead(X)*0.0048828125 - 1.66;
GX = GX / 0.333;
printDouble(GX, 4);
delay(100);
}
This one will go all the way from 0-0.99 and then suddenly go to correct negativ value of -1.0.....
#include <Arial14.h>
#include <ks0108.h>
int X = 5;
///////////////////////////////////////////////////////////////////////////////////// printDouble
void printDouble( double val, byte precision){
// prints val with number of decimal places determine by precision
// precision is a number from 0 to 6 indicating the desired decimial places
// example: printDouble( 3.1415, 2); // prints 3.14 (two decimal places)
GLCD.PrintNumber( (long)val); //prints the int part
if( precision > 0) {
GLCD.PutChar('.');
unsigned long frac;
unsigned long mult = 1;
byte padding = precision -1;
while(precision--)
mult *=10;
if(val >= 0)
frac = (val - int(val)) * mult;
else
frac = (int(val)- val ) * mult;
unsigned long frac1 = frac;
while( frac1 /= 10 )
padding--;
while( padding--)
GLCD.PutChar('0');
GLCD.PrintNumber(frac) ;
}
}
float drawSine(int angle){
float sine;
// if(angle <= 0)
sine = sin(PI / 180 * angle);
return sine;
}
//////////////////////////////////////////////////////////////////////////
void setup(){
GLCD.Init(NON_INVERTED);
GLCD.SelectFont(Arial_14);
Serial.begin(9600);
}
void loop(){
float GX = analogRead(X)*0.0048828125 - 1.66;
GX = GX / 0.333;
GLCD.FillRect(04, 45, 100, 15, WHITE);
GLCD.GotoXY(05, 45);
printDouble(GX, 2);
delay(100);
}
Good to have you back mem and thanks for the fast reply mikalhart!