When I use an analog input on a uLCD-35DT with touch enabled and I press the screen the analog values rise (if pin not connected to around 1V). If I release it, it works properly(shows zero). Has anyone got an idea or any experience as to why this is? I'm using the latest driver and loader. Here is my test code: #platform "uLCD-35DT"
// Program Skeleton 1.2 generated 31.3.2016 14:36:58
#inherit "4DGL_16bitColours.fnc"
#inherit "VisualConst.inc"
#inherit "visi testConst.inc"
#inherit "ledDigitsDisplay.inc"
var Voltage := 0;
var Vsteps := 0;
var state;
func main()
// var hstrings ; // Handle to access uSD strings, uncomment if required
// var hFontx ; // Handle to access uSD fonts, uncomment if required and change n to font number
// Uncomment the following if uSD images, fonts or strings used.
putstr("Mounting...\n");
if (!(file_Mount()))
while(!(file_Mount()))
putstr("Drive not mounted...");
pause(200);
gfx_Cls();
pause(200);
wend
endif
// gfx_TransparentColour(0x0020); // uncomment if transparency required
// gfx_Transparency(ON); // uncomment if transparency required
// hFontn := file_LoadImageControl("VISITE~1.dan", "VISITE~1.gcn", 1); // Open handle to access uSD fonts, uncomment if required and change n to font number dropping a and c if > 9
// hstrings := file_Open("VISITE~1.txf", 'r') ; // Open handle to access uSD strings, uncomment if required
hndl := file_LoadImageControl("VISITE~1.dat", "VISITE~1.gci", 1);
touch_Set(TOUCH_ENABLE);
pin_Set(PIN_AN, PA1);
gfx_Set(SCREEN_MODE,LANDSCAPE) ;
// Form1 1.1 generated 31.3.2016 14:38:26
gfx_BGcolour(0x63C8) ;
gfx_Cls() ;
// 4Dbutton1 1.0 generated 1.4.2016 8:23:52
img_ClearAttributes(hndl, i4Dbutton1, I_TOUCH_DISABLE); // set to enable touch, only need to do this once
img_Show(hndl, i4Dbutton1); // show button, only do this once
img_SetWord(hndl, i4Dbutton1, IMAGE_INDEX, state); // where state is 0 for up and 1 for down
img_Show(hndl,i4Dbutton1) ;
// Userled1 1.0 generated 1.4.2016 8:31:48
img_Show(hndl,iUserled1) ; // show initialy, if required
img_SetWord(hndl, iUserled1, IMAGE_INDEX, 0) ; // where numx is 0 (Off) or 1 (On)
img_Show(hndl,iUserled1) ;
// Strings1 1.1 generated 1.4.2016 9:19:41
txt_FontID(FONT3) ;
txt_FGcolour(WHITE) ;
txt_BGcolour(BLACK) ;
gfx_MoveTo(0 , 0) ;
print(Voltage) ;
sys_SetTimer(TIMER0, 1000);
repeat
state := touch_Get(TOUCH_STATUS);
if(state == TOUCH_PRESSED)
img_SetWord(hndl, iUserled1, IMAGE_INDEX, 1) ; // where numx is 0 (Off) or 1 (On)
img_Show(hndl,iUserled1) ;
else if(state == TOUCH_RELEASED)
img_SetWord(hndl, iUserled1, IMAGE_INDEX, 0) ; // where numx is 0 (Off) or 1 (On)
img_Show(hndl,iUserled1) ;
endif
if(sys_GetTimer(TIMER0)== 0)
getAnalog();
sys_SetTimer(TIMER0, 1000);
endif
forever
endfunc
func getAnalog()//read AI
Vsteps := pin_Read(PA1) ;
getVoltage(Vsteps);
endfunc
func getVoltage(var reading) //Direct Voltage
var nsteps[2];
var Vref[2];
var Nsteps[2];
var Factor[2];
var Result[2];
flt_VAL(Vref, "3.3"); //Convert a string ("3.3") to a float (Vref)
flt_ITOF(Nsteps, 4095); //Convert an integer (4095) to a float (Nsteps)
flt_DIV(Factor, Vref, Nsteps); //Float divistion, Factor = Vref/Nsteps
flt_ITOF(nsteps, reading); //Convert the integer 'reading' to a float 'nsteps'
flt_MUL(Result, nsteps, Factor);//Float multiplication, Result = nsteps * Factor
flt_PRINT(Result, "%.4f");
Voltage := flt_FTOI(Result);
endfunc