demo to show the touchscreen and TFT use
the updated code:
The touchscreen lib:
The TFT lib:
Connection to the mbed
The connection to the TFT : http://mbed.org/users/dreschpe/notebook/qvga-tft-with-hx8347d-controller/
To use the touchscreen we need 4 additional pins - 2 IO and 2 Analog Input pins. The pins on the tft are labeled with x+ x- y+ and y-. The x+ and y+ signal has to be connected to a analog input pin of the mbed. (Pin 15 - 20).
The lib is using the pullups inside the mbed pins, so we do not need resistors.
Use the touch
The x- and y- signals can also connected to a digital io pin. In my demo i use the four analog pins p19,p20,p16 and p17.
If you use the SPI on pin 5 to 7 to control the TFT like the schematic on http://mbed.org/users/dreschpe/notebook/touchscreen/ please change the next line
touch_tft tt(p19,p20,p16,p17,p11, p12, p13, p14, p15,"TFT"); // x+,x-,y+,y-,mosi, miso, sclk, cs, reset
tt is the touch screen objekt. To get the position on the screen we have to calibrate the touch screen first. The function
first draw a cross in the left corner. You have to touch this cross and after that the cross on the right. Both analog values are calibrated and we can calcuate the position x,y coresponding to the pixel address.
To use positions we have to declare a variable from type point fist. This variable has a x and y member :
Then we ask for the position:
p = tt.get_touch();
p hold the analog x and y position. With the function
we can test if the screen is touched. If so, we use the function
p = tt.to_pixel(p);
to convert the point to a pixel address. p.x and p.y are the pixel address now. This is the input to use inside our program.
We can draw a circle at the point
Have fun, Peter
4 comments on micro paint:
Please log in to post comments.