I have a tft lcd touch and rtc on my arduino, i drew 0 to 9 numbers on the lcd and have the x,y touch coordinates to define the 10 numbers. I want to do is afther pressing to numbers ex 1 and 3 (13) send them to rtc ( ds1307setup(); ) i change the numers in ds1307set(DS1307_....,mi); to diferent int in order to geting the touch data but dont now how to transform the x,y to a int.
I need to "store" 5 "var" before send the ds1307setup(); (year = int y, month = int m, day = int d....)
ds1307set(DS1307_SEG,1);
ds1307set(DS1307_MIN,mi); // mi
ds1307set(DS1307_HR,h); // h
ds1307set(DS1307_DdS,ds); // ds
ds1307set(DS1307_DMES,dm); // dm
ds1307set(DS1307_MTH,me); // me
ds1307set(DS1307_ANO,a); // a
Please help me or if there is a example made point me there.
You mean the x and y coordinates? Just use IF/ELSE statements.
Example:
if x == 0 and y == 3, button 3 was pressed.
if x == 1 and y == 5, button 7 was pressed.
You have to map out where each button its and set it in the IF/ELSE statements. You will need 2 X coords(left / right of button) and 2 Y coords(top / bottom of button) to do it properly.
You should check for a special character button like * or # and if any of those are pressed it convert the array to an int. If those are NOT pressed, use a variable (int counter;) to add number to the array.
Same way. the only time it stops entering number is when one of those special characters are pressed. You should also clear the array afterwards with a while loop.
while(counter != 0) { // this can be used for any size array.
myInts[counter--] = 0;
}
My doubts is afther pressing a number how do i store it? in the array in a char??
Please write example they way i talking about (my Inglish is not very good)
if (page == 70 && p.y > 211 && p.y < 231 && p.x > 84 && p.x <104 ){ // im guessing button ZERO
tft.setTextSize(3);
tft.fillRect(82, 201, 25, 25, BLUE);
tft.setCursor(82, 201);
tft.println ("0");
myInts[counter++] = '0'; // *** this is the setup needed *** the numbers must go between single quotes ' '
// Everytime you press a button, counter updates and the char is stored
// If special button is pressed, convert data in array.
}
else if (page == 70 && p.y > 290 && p.y < 310 && p.x > 190 && p.x <215 && q==1){ // Button ONE
tft.setTextSize(3);
tft.fillRect(110, 201, 25, 25, BLUE);
tft.setCursor(110, 201);
tft.println ("1");
myInts[counter++] = '1';
}
. TWO
. THREE
. FOUR
And so on
Added: You also need to make sure you set the counter back to zero after you convert the array to an int.
Thankz a lot, afther i press 0 and then 1 i press the special button convert data in array i get myInts[0] = 0 and myInts[1] = 1 and myInts[] = 01 write? then a = atoi(myInts);