ColorTFTTouchSamples
Touch Screen Samples
I will be posting some samples here for the TFT Touch Module, I hope someone will find them useful.
The Touch module can be found here: TFT Touch Module.
The Touch module also uses the Firewing Color TFT Library, more infomation can be found here: Firewing TFT Library.
Drawing
This is a simple drawing programme, just use a stylus and draw anything you wish!.
As you can see from the image that I'm not much of an artist, but you get the idea.
Download the Drawing Sample code here: DrawingV1.0.zip
' set high speed clock and import modules... clock = 80 imports Tft imports TftGraphic imports TFTTouch ' program entry point Sub Main() Tft.Clear() Tft.SetPenColor(255,255,255) while true if Touch.Available() then Touch.Read() Tft.SetPixel(Touch.GetXPos(),Touch.GetYPos()) end if end while End Sub ' disable UART1 on pins D0 and D1... sub OnStartup() Handles PIC.OnStartup RPINR18 = RPINR18 or &H001F ' disable Uart1 RX RPOR2 = RPOR2 and &HE0FF ' disable Uart1 TX end sub
Buttons
This is a demo to show how you can draw some buttons on the TFT screen and use the Touch Screen to show which button was pressed.
Download the Buttons Sample code here: ButtonsV1.0.zip
Note, The download includes the font that I used within the programme.
Video of Button Demo * Button Demo
' set high speed clock and import modules... clock = 80 imports Tft imports TftGraphic imports CourierNew imports TFTTouch ' program entry point Sub Main() Tft.Clear Brush.Style = BrushStyle.IsClear SetFont(CourierNew) DrawButtons() Tft.WriteAt(160,100, "Button ?") while true if Touch.Available() then CheckButtonsPressed() end if end while End Sub sub CheckButtonsPressed() dim btn1 as byte = 35 dim btn2 as byte = 98 dim btn3 as byte = 160 dim btn4 as byte = 220 dim btn5 as ushort = 283 dim x,y as ushort Touch.Read() x = Touch.GetXPos() y = Touch.GetYPos() if y >= 20 and y <= 50 then select case x case btn1-20 to btn1+20 Tft.SetBrushColor(0,0,0) Tft.FillRect(160,100,319,120) Tft.WriteAt(160,100,"Button 1") case btn2-20 to btn2+20 Tft.SetBrushColor(0,0,0) Tft.FillRect(160,100,319,120) Tft.WriteAt(160,100,"Button 2") case btn3-20 to btn3+20 Tft.SetBrushColor(0,0,0) Tft.FillRect(160,100,319,120) Tft.WriteAt(160,100,"Button 3") case btn4-20 to btn4+20 Tft.SetBrushColor(0,0,0) Tft.FillRect(160,100,319,120) Tft.WriteAt(160,100,"Button 4") case btn5-20 to btn5+20 Tft.SetBrushColor(0,0,0) Tft.FillRect(160,100,319,120) Tft.WriteAt(160,100,"Button 5") end select end if do loop until not Touch.Available() delayms(250) end sub sub DrawButtons() for x as byte = 0 to 4 Tft.SetBrushColor(0, 0, 255) Tft.FillRoundRect(10+(x*60), 10, 60+(x*60), 60) Tft.SetBrushColor(255, 255, 255) Tft.RoundRect(10+(x*60), 10, 60+(x*60), 60) Tft.WriteAt(28+(x*60),24, str(x+1)) next end sub ' disable UART1 on pins D0 and D1... sub OnStartup() Handles PIC.OnStartup RPINR18 = RPINR18 and &HFFE0 RPOR2 = RPOR2 and &HE0FF end sub