Hi,
Here is the deal. I am currently building a portable CNC system based on Roxen's Polar plotter.
Video link to roxen's plotter
However i am using a resistive touchscreen (3.5" TFT LCD MCUfriend) to input data to an Arduino mega. i have some canned routines such as rectangles and squares.
Hence the user can input the length and width of the rectangle and then press enter and off the machine go.
I have somewhat successfully managed to display the numbers in their respective field.
My problem now is actually using these values.
Currently i have a global variable called digit.
So basically when the user press a number, it is displayed in the selected field and digit is increased by 1. Then if another number is pressed the same thing occur.
Here is an image
my thinking was to use digit as an index to store the each number press in a string and using digit to reference the position of the value in the string.
Then finally convert that string to a float for use by a function.
Is there a better way to implement this if not how can i convert a string to float value.
I would be very grateful if someone could point me in the right direction.
this part is used to detect what field is being selected and reset digit to 0.
The import bit is the //enter
case 2:{// =Rectangle
KeyPadPress();
if (tp.z>=pressure)
{
if (px>30&&px<130 && py>196&&py<256)// menu
{
RectangleMenu(1);
BackGround();
Rectanglefield=0;
Page=0;
if (Electromagnet==false)
{
HomeScreen(2);
}
else
{
HomeScreen(0);
}
}
else if (px>170&&px<270 && py>196&&py<256)// Enter
{
RectangleMenu(2);
}
else if (px>125&&px<425 && py>20&&py<28)//Width
{
Rectanglefield=1;
digit=0;
RectangleMenu(3);
}
else if (px>125&&px<425 && py>59&&py<87)//Length
{
Rectanglefield=2;
digit=0;
RectangleMenu(4);
}
}
break;
}
This is used to input numbers to the selected field.
Most important bit start at if (digit<=3)
Width and LenghtR are global chars
void KeyPadPress()
{
int x=300, y=110;
int bDimension= 43, spacex=13, spacey=8;
int fieldx=500,fieldy=500;
char field;
static int fieldstartx;
static int fieldstarty;
int delfieldY,delfieldX;
if (tp.z>=pressure)
{
switch (Page) {
case 2://Rectangle
{
if (Page ==2)
{
fieldstartx=130;
}
if(Rectanglefield==0)
{
digit=4;
}
else if (Rectanglefield==1){
fieldx= fieldstartx+(digit*digitcoor);fieldy=30;
fieldstartx=130;
}
else if (Rectanglefield==2){
fieldx= fieldstartx+(digit*digitcoor);fieldy=66;
fieldstartx=130;
}
if (digit<=3)
{
if (px>x&&px<x+bDimension && py>y&&py<y+bDimension)// 1
{
KeyPad(1);
myGLCD.setColor(0,0,0);
myGLCD.print("1",fieldx,fieldy);
if (Rectanglefield==1)
{
Width[digit]='1';
}
else{
LengthR[digit]='1';
}
digit++;
}
if (px>x+(spacex+bDimension)&&px<x+bDimension+(spacex+bDimension) && py>y&&py<y+bDimension)// 2
{
KeyPad(2);
myGLCD.setColor(0,0,0);
myGLCD.print("2",fieldx,fieldy);
digit++;
}
if (px>x+ 2*(spacex+bDimension)&&px<x+bDimension+2*(spacex+bDimension) && py>y&&py<y+bDimension)// 3
{
KeyPad(3);
myGLCD.setColor(0,0,0);
myGLCD.print("3",fieldx,fieldy);
digit++;
}
if (px>x&&px<x+bDimension && py>y +(spacey+bDimension)&&py<y +(spacey+bDimension)+bDimension)// 4
{
KeyPad(4);
myGLCD.setColor(0,0,0);
myGLCD.print("4",fieldx,fieldy);
digit++;
}
if (px>x+ (spacex+bDimension)&&px<x+ (spacex+bDimension)+bDimension && py>y+ (spacey+bDimension)&&py<y+ (spacey+bDimension)+bDimension)// 5
{
KeyPad(5);
myGLCD.setColor(0,0,0);
myGLCD.print("5",fieldx,fieldy);
digit++;
}
if (px>x+ 2*(spacex+bDimension)&&px<x+ 2*(spacex+bDimension)+bDimension && py>y+ (spacey+bDimension)&&py<y+ (spacey+bDimension)+bDimension)// 6
{
KeyPad(6);
myGLCD.setColor(0,0,0);
myGLCD.print("6",fieldx,fieldy);
digit++;
}
if (px>x&&px<x+bDimension && py>y+ 2*(spacey+bDimension)&&py<y+ 2*(spacey+bDimension)+bDimension)// 7
{
KeyPad(7);
myGLCD.setColor(0,0,0);
myGLCD.print("7",fieldx,fieldy);
digit++;
}
if (px>x+ (spacex+bDimension)&&px<x+ (spacex+bDimension)+bDimension && py>y+ 2*(spacey+bDimension)&&py<y+ 2*(spacey+bDimension)+bDimension)// 8
{
KeyPad(8);
myGLCD.setColor(0,0,0);
myGLCD.print("8",fieldx,fieldy);
digit++;
}
if (px>x+ 2*(spacex+bDimension)&&px<x+ 2*(spacex+bDimension)+bDimension && py>y+ 2*(spacey+bDimension)&&py<y+ 2*(spacey+bDimension)+bDimension)// 9
{
KeyPad(9);
myGLCD.setColor(0,0,0);
myGLCD.print("9",fieldx,fieldy);
digit++;
}
if (px>x&&px<x+bDimension && py>y+ 3*(spacey+bDimension)&&py<y+ 3*(spacey+bDimension)+bDimension)// C
{
KeyPad(10);
myGLCD.setColor(255,255,255);
myGLCD.fillRect(130,fieldy,220,fieldy+14);
digit=0;
}
if (px>x+ (spacex+bDimension)&&px<x+ (spacex+bDimension)+bDimension && py>y+ 3*(spacey+bDimension)&&py<y+ 3*(spacey+bDimension)+bDimension)// 0
{
KeyPad(11);
myGLCD.setColor(0,0,0);
myGLCD.print("0",fieldx,fieldy);
digit++;
}
if (px>x+ 2*(spacex+bDimension)&&px<x+ 2*(spacex+bDimension)+bDimension && py>y+ 3*(spacey+bDimension)&&py<y+ 3*(spacey+bDimension)+bDimension)// .
{
KeyPad(12);
if (digit==0)
{
myGLCD.setColor(0,0,0);
myGLCD.print("0.",fieldx,fieldy);
fieldstartx=fieldstartx+20;
}
else{
myGLCD.setColor(0,0,0);
fieldx=fieldx-10;
fieldstartx=130;
myGLCD.print(".",fieldx,fieldy);
}
}
}//case 2 if digit
else {
if (px>x&&px<x+bDimension && py>y+ 3*(spacey+bDimension)&&py<y+ 3*(spacey+bDimension)+bDimension)// C
{
KeyPad(10);
myGLCD.setColor(255,255,255);
myGLCD.fillRect(130,fieldy,220,fieldy+14);
digit=0;
}
}//if digit is>= 3 else end
break;
}//end case 2