ColorTFTSamples

Here are some samples using the Firewing Color TFT Library.

These samples will be included with Firewing 1.0.0.1 (BETA Version) onwards, you will find them in the Samples folder TFT.

Download Firewing (Beta) from here: Firewing Beta

Note: These samples use Modules that are not included at present in the Beta Version of the Compiler, you will need to find them within the samples folder.

Arduino


This is a full port of the Arduino TFT display Demo.

*Arduino Sample Video

' demo ported from
' UTFT_Demo_320x240 by 2012 Henning Karlsen
' web: http://www.henningkarlsen.com/electronics

' set high speed clock and import modules...
clock = 80
imports Tft
imports TftGraphic
imports FixedFont
imports VerdanaFont
imports Math

' program entry point...
Sub Main()

   ' drwa header and footer
   Tft.Clear()  
   Tft.SetBrushColor(255, 0, 0)
   Tft.FillRect(0, 0, 319, 13)
   Tft.SetBrushColor(64, 64, 64)
   Tft.FillRect(0, 226, 319, 239)                          
   Tft.SetFont(Fixed)
   Tft.Brush.Style = BrushStyle.IsClear
   Tft.Graphic.Align = TextAlign.Center
   Tft.SetPenColor(255, 255, 255)
   Tft.WriteStr(160,3,"* Firewing Color Tft Display Library *")
   Tft.SetPenColor(255,255,0)
   Tft.WriteStr(160,229,"<http://www.firewing.info>")

   ' drwa border
   Tft.SetPenColor(255,255,255)
   Tft.SetBrushColor(0, 0, 255)
   Tft.Rect(0, 14, 319, 225)

   ' draw crosshairs
   Tft.SetPenColor(0, 0, 255)
   Tft.setBrushColor(0, 0, 0)
   Tft.Line(159, 15, 159, 224)
   Tft.Line(1, 119, 318, 119)
   for i as ushort = 9 to 310 step 10
      Tft.Line(i, 117, i, 121) 
   next
   for i as ushort = 19 to 220 step 10
      Tft.Line(157, i, 161, i)    
   next    

   ' Draw sin-, cos- and tan-lines  
   Tft.SetPenColor(0,255,255)
   Tft.WriteAt(5,15,"Sin")
   for i as ushort = 1 to 317
      Tft.SetPixel(i,119 + (sin(((i*1.13)*3.14)/180)*95))
   next

   Tft.SetPenColor(255,0,0)
   Tft.WriteAt(5,27,"Cos")
   for i as ushort = 1 to 317
      Tft.SetPixel(i,119+(cos(((i*1.13)*3.14)/180)*95))
   next

   Tft.SetPenColor(255,255,0)
   Tft.WriteAt(5,39,"Tan")
   for i as ushort = 1 to 317
      Tft.SetPixel(i,119+(tan(((i*1.13)*3.14)/180)))
   next
   delayms(2000)

   Tft.SetBrushColor(0,0,0)
   Tft.FillRect(1,15,318,224)
   Tft.SetPenColor(0, 0, 255)
   Tft.SetBrushColor(0, 0, 0)
   Tft.Line(159, 15, 159, 224)
   Tft.Line(1, 119, 318, 119)

   ' draw a moving sinewave 
   dim buf(318) as ushort 
   buf(0) = nothing
   dim x as ushort = 1    
   dim y as ushort
   for i as ushort = 1 to 318 * 20 - 1
      x += 1
      if x = 319 then x = 1
      if i > 319 then
         if (x = 159) or (buf(x-1) = 119) then
            Tft.SetPenColor(0,0,255)
         else
            Tft.SetPenColor(0,0,0)
         end if
         Tft.SetPixel(x,buf(x-1))
      end if
      Tft.SetPenColor(0,255,255)
      y = 119+(sin(((i*1.1)*3.14)/180) * (90-(i / 100)))
      Tft.SetPixel(x,y)
      buf(x-1)=y
   next
   delayms(2000)

   ' draw some filled rectangles 
   Tft.SetBrushColor(0,0,0)
   Tft.FillRect(1,15,318,224)
   for i as ushort = 1 to 5
      select i
         case 1 : Tft.SetBrushColor(255,0,255)
         case 2 : Tft.SetBrushColor(255,0,0)
         case 3 : Tft.SetBrushColor(0,255,0)
         case 4 : Tft.SetBrushColor(0,0,255)
         case 5 : Tft.SetBrushColor(255,255,0)
      end select
      Tft.FillRect(70+(i*20), 30+(i*20), 130+(i*20), 90+(i*20))
   next

   delayms(2000) 

   ' draw some filled, rounded rectangles
   Tft.setBrushColor(0,0,0)
   Tft.FillRect(1,15,318,224)
   for i as ushort = 1 to 5
      select i
         case 1 : Tft.SetBrushColor(255,0,255)
         case 2 : Tft.SetBrushColor(255,0,0)
         case 3 : Tft.SetBrushColor(0,255,0)
         case 4 : Tft.SetBrushColor(0,0,255)
         case 5 : Tft.SetBrushColor(255,255,0)
      end select
      Tft.fillRoundRect(190-(i*20), 30+(i*20), 250-(i*20), 90+(i*20))
   next 
   delayms(2000) 

   ' draw some filled circles   
   Tft.SetBrushColor(0,0,0)
   Tft.FillRect(1,15,318,224)
   for i as ushort = 1 to 5
      select i
         case 1 : Tft.SetBrushColor(255,0,255)
         case 2 : Tft.SetBrushColor(255,0,0)
         case 3 : Tft.SetBrushColor(0,255,0)
         case 4 : Tft.SetBrushColor(0,0,255)
         case 5 : Tft.SetBrushColor(255,255,0)
      end select 
      Tft.fillCircle(100+(i*20),60+(i*20), 30)
   next
   delayms(2000)

   ' draw some lines in a pattern 
   Tft.setBrushColor(0,0,0)
   Tft.FillRect(1,15,318,224)
   Tft.setPenColor (255,0,0)
   for i as ushort = 15 to 223 step 5
      Tft.Line(1, i, (i*1.44)-10, 224)
   next

   Tft.setPenColor (255,0,0)
   for i as ushort = 224 to 16 step -5
      Tft.Line(318, i, (i*1.44)-11, 15)
   next

   Tft.setPenColor (0,255,255)
   for i as ushort = 224 to 16 step -5
      Tft.Line(1, i, 331-(i*1.44), 15)
   next

   Tft.SetPenColor (0,255,255)
   for i as ushort = 15 to 223 step 5
      Tft.Line(318, i, 330-(i*1.44), 224)
   next
   delayms(2000)

   ' draw some random circles  
   Tft.SetBrushColor(0,0,0)
   Tft.FillRect(1,15,318,224)
   dim r as ushort 
   for i as ushort = 0 to 99
      Tft.setPenColor(Random(255), Random(255), Random(255))
      x=32+Random(256)
      y=45+Random(146)
      r= 5 + Random(25)
      Tft.Circle(x, y, r)    
   next
   delayms(2000)

   ' draw some random rectangles 
   Tft.setBrushColor(0,0,0)
   Tft.FillRect(1,15,318,224)
   dim x2 as ushort
   dim y2 as ushort
   for i as ushort = 0 to 99
      Tft.setPenColor(Random(255), Random(255), Random(255))
      x=2+Random(316)
      y=16+Random(207)
      x2=2+Random(316)
      y2=16+Random(207)
      Tft.Rect(x, y, x2, y2)
   next
   delayms(2000)

   ' draw some random rounded rectangles
   Tft.setBrushColor(0,0,0)
   Tft.FillRect(1,15,318,224)
   for i as ushort = 0 to 99
      Tft.setPenColor(Random(255), Random(255), Random(255))
      x=2+Random(316)
      y=16+Random(207)
      x2=2+Random(316)
      y2=16+Random(207)
      Tft.RoundRect(x, y, x2, y2)
   next
   delayms(2000)

   ' draw some random lines
   Tft.setBrushColor(0,0,0)
   Tft.FillRect(1,15,318,224)
   for i as ushort = 0 to 99
      Tft.setPenColor(Random(255), Random(255), Random(255))
      x=2+Random(316)
      y=16+Random(209)
      x2=2+Random(316)
      y2=16+Random(209)
      Tft.Line(x, y, x2, y2)
   next
   delayms(2000)

   ' draw some random dots 
   Tft.setBrushColor(0,0,0)
   Tft.FillRect(1,15,318,224)
   for i as ushort = 1 to 10000
      Tft.setPenColor(Random(255), Random(255), Random(255))
      Tft.SetPixel(2+Random(316), 16+Random(209))
   next   

   ' display finished
   Tft.SetFont(VerdanaBold)
   Tft.SetPenColor(255,255,255)  
   Tft.WriteStr(160,100,"FINISHED") 
end sub

' disable UART1 on pins D0 and D1...
sub OnStartup() Handles PIC.OnStartup
   RPINR18 = RPINR18 or &H001F
   RPOR2 = RPOR2 and &HE0FF    
end sub

' Random routine...
Public Function Random(rndMax as ushort) As UShort
   static LCG as ushort = 21844 
   static GLFSR As UShort = 1
   LCG = (127 * LCG + 259) 
   If (GLFSR And 1) = 1 Then
      GLFSR = GLFSR Xor 447 
      GLFSR = (GLFSR >> 1) Or &H8000
   Else
      GLFSR = (GLFSR >> 1)
   End If
   return (GLFSR Xor LCG) mod rndMax 
End Function

Fonts


This is an example of using Fonts with the Firewing Color TFT Library.

' set high speed clock and import modules...
clock = 80
imports Tft
imports TftGraphic
imports VerdanaFont
imports BookmanFont

' program entry point
Sub Main()
   Tft.Clear  
   Tft.Brush.Style = BrushStyle.IsClear
   Tft.SetFont(Verdana)  
   Tft.WriteAt(10,10,"Verdana")  
   Tft.SetFont(VerdanaBold)
   Tft.WriteAt(10,35,"Verdana Bold") 
   Tft.SetFont(VerdanaItalic)
   Tft.WriteAt(10,60,"Verdana Italic") 
   Tft.SetFont(VerdanaBoldItalic)
   Tft.WriteAt(10,85,"Verdana Bold Italic")

   Tft.SetFont(Bookman)  
   Tft.WriteAt(10,120,"Bookman")
   Tft.SetFont(BookmanBold)  
   Tft.WriteAt(10,145,"Bookman Bold") 
   Tft.SetFont(BookmanItalic)  
   Tft.WriteAt(10,170,"Bookman Italic") 
   Tft.SetFont(BookmanBoldItalic)  
   Tft.WriteAt(10,195,"Bookman Bold Italic")    
End Sub

' disable UART1 on pins D0 and D1...
sub OnStartup() Handles PIC.OnStartup
   RPINR18 = RPINR18 or &H001F
   RPOR2 = RPOR2 and &HE0FF    
end sub

Graphics

Two examples on using Graphics with the Firewing Color TFT Library.

Squares and Circles



' set high speed clock and import modules...
clock = 80
imports Tft
imports TftGraphic

' program antry point...
Sub Main()
   Tft.Clear()
   DoCircles()
   delayms(1000)
   DoSquares()
End Sub

' disable UART1 on pins D0 and D1...
sub OnStartup() Handles PIC.OnStartup
   RPINR18 = RPINR18 or &H001F
   RPOR2 = RPOR2 and &HE0FF   
end sub

' draw circles...
sub DoCircles()
   const radius = 25
   const xstart = 35
   const ystart = 35
   dim colors() as ushort = {&H0000, &HFFFF, &HF800, &H0400, &H07E0, &H001F, &H001A,_
                             &HC618, &H8410, &H000F, &H8000, &HFFE0, &H8400, &H07E0,_
                             &H07FF, &H0410, &H0010, &HF81F, &H8010, &HA000}              
   dim x as ushort = xstart
   dim y as ushort = ystart
   dim index as byte = 0

   while index <= ubound(colors)
      Tft.SetBrushColor(0,0,0)
      Tft.FillRect(x - radius - 1, y - radius, x + radius, y + radius)

      Tft.SetBrushColor(colors(index))
      Tft.FillCircle(x,y, radius)
      Tft.Circle(x,y,radius - 1) 
      x += (radius * 2 + 5)
      if x > Tft.Width - (radius * 2) - 5 then 
         y += radius * 2 + 5  
         x = xstart
      end if 
      index += 1
   end while
end sub

' draw squares...
sub DoSquares()
   const width = 50
   const height = 50  
   const xstart = 10
   const ystart = 10
   dim colors() as ushort = {&H0000, &HFFFF, &HF800, &H0400, &H07E0, &H001F, &H001A,_
                             &HC618, &H8410, &H000F, &H8000, &HFFE0, &H8400, &H07E0,_
                             &H07FF, &H0410, &H0010, &HF81F, &H8010, &HA000}              
   dim x as ushort = xstart
   dim y as ushort = ystart
   dim index as byte = 0

   while index <= ubound(colors)
      Tft.SetBrushColor(colors(index))
      Tft.FillRect(x,y,x + width,y + height)
      Tft.Rect(x,y,x + width,y + height) 
      x += (width + 5)
      if x > Tft.Width - width - 5 then 
         y += height + 5  
         x = xstart
      end if 
      index += 1
   end while
end sub

Spectrum



' set high speed clock and import modules...
clock = 80
imports Tft
imports TftGraphic
imports FixedFont
imports Math

' constants and variables...
dim bars(15) as ushort
const BASE_LINE = 200

' program entry point...
Sub Main()
   Tft.Clear   

   ' base line line
   Tft.SetPenColor(255,255,255)
   Tft.Line(12,BASE_LINE + 4,width - 12, BASE_LINE + 4)
   Tft.Line(12,BASE_LINE + 5,width - 12, BASE_LINE + 5)  

   ' base line marks
   for x as ushort = 19 to 300 step 20
      Tft.Line(x,BASE_LINE + 6,x, BASE_LINE + 9)
      Tft.Line(x + 1,BASE_LINE + 6,x + 1, BASE_LINE + 9)       
   next   

   ' display text...
   Tft.Brush.Style = BrushStyle.IsClear
   Tft.Graphic.Align = TextAlign.Center
   Tft.SetPenColor(255, 255, 255)  
   Tft.SetFont(Fixed)
   Tft.WriteStr(160, BASE_LINE + 14,"FREQUENCY")

   ' loop forever...
   while true  

      ' init and draw randow bars - do this 10 times...
      for count as ushort = 1 to 10 
         for i as ushort = 0 to ubound(bars)
            bars(i) = 10 + random(90)
         next
         DrawBars()
      next

      ' init random bars, then display decreasing each
      ' time - do this 5 times...
      for count as ushort = 1 to 5
         for i as ushort = 0 to ubound(bars)
            bars(i) = 10 + random(90)
         next
         DrawBars()

         for delay as ushort = 1 to 5
            for i as ushort = 0 to ubound(bars)
               if bars(i) > 5 then bars(i) = bars(i) - 5
            next
            DrawBars()
         next  
      next 
   end while
End Sub

' set a color value based on index lookup...
sub MapColorByIndex(index as byte)
   select index
      case 1 : Tft.SetBrushColor(126,246,34) 
      case 2 : Tft.SetBrushColor(138,231,20)
      case 3 : Tft.SetBrushColor(152,233,30)
      case 4 : Tft.SetBrushColor(155,231,21)
      case 5 : Tft.SetBrushColor(168,227,23)
      case 6 : Tft.SetBrushColor(181,226,19)
      case 7 : Tft.SetBrushColor(198,228,34)
      case 8 : Tft.SetBrushColor(203,219,32)
      case 9 : Tft.SetBrushColor(210,214,41)
      case 10: Tft.SetBrushColor(211,204,28)
      case 11: Tft.SetBrushColor(216,194,22)
      case 12: Tft.SetBrushColor(220,181,26)
      case 13: Tft.SetBrushColor(224,171,29)
      case 14: Tft.SetBrushColor(219,159,11)
      case 15: Tft.SetBrushColor(226,155,3)
      case 16: Tft.SetBrushColor(236,138,11)
      case 17: Tft.SetBrushColor(236,127,8)
      case 18: Tft.SetBrushColor(231,114,9)
      case 19: Tft.SetBrushColor(239,107,6)
      case 20: Tft.SetBrushColor(237,99,1) 
   end select
end sub

' draw a single bar...
sub DrawBar(x as ushort, value as short)
   const BAR_WIDTH = 15
   const BAR_HEIGHT = 5
   const BAR_SPACE = 3
   dim y as ushort = BASE_LINE    
   for i as byte = 1 to 20 
      if value <= 0 then 
         Tft.SetBrushColor(50,50,50)   
      else
         MapColorByIndex(i)
      end if  
      Tft.FillRect(x, y, x + BAR_WIDTH, y - BAR_HEIGHT)
      value -= BAR_HEIGHT    
      y -= (BAR_HEIGHT + BAR_SPACE) 
   next
end sub

' draw all of the bars...
sub DrawBars()
   dim x as ushort = 12
   for index as ushort = 0 to ubound(bars)
      DrawBar(x, bars(index))  
      x += 20       
   next  
end sub

' disable UART1 on pins D0 and D1...
sub OnStartup() Handles PIC.OnStartup
   RPINR18 = RPINR18 or &H001F
   RPOR2 = RPOR2 and &HE0FF    
end sub

' random routine...
Public Function Random(rndMax as byte) As byte
   static LCG as byte = 84
   static GLFSR As Byte = 1
   LCG=(7 * LCG + 17) 
   If (GLFSR And 1) = 1 Then
      GLFSR = GLFSR Xor 135
      GLFSR = (GLFSR >> 1) Or &H80
   Else
      GLFSR = (GLFSR >> 1)
   End If
   return (GLFSR Xor LCG) mod rndMax 
End Function

Images

Images stored in ROM


' set high speed clock and import modules...
clock = 80
imports Tft
imports TftGraphic
imports FirewingLogoImage
imports RingImage

' program entry point...
Sub Main()
   tft.Clear(&HFFFF)
   tft.SetBitmap(10,30,FirewingLogo)
   tft.SetBitmap(100,90, Ring)
End Sub

' disable UART1 on pins D0 and D1...
sub OnStartup() Handles PIC.OnStartup
   RPINR18 = RPINR18 or &H001F
   RPOR2 = RPOR2 and &HE0FF    
end sub

SD Card images


Reading images from a SD Card

Images created using the Image Converter plugin. You can download a set of images used in this demo from here:


' set high speed clock and import modules...
clock = 80
imports Tft
imports TftGraphic
imports Sd
imports FixedFont

' display bitamp from SD card...
function SetBitmap(x as ushort, y as ushort, filename as string) as byte
   dim data as ushort
   dim width as ushort
   dim height as ushort

   SetBitmap = SD.Open(filename)
   if SetBitmap = errOK then
      width.Byte0 = SD.ReadByte
      width.Byte1 = SD.ReadByte       
      height.Byte0 = SD.ReadByte
      height.Byte1 = SD.ReadByte

      Tft.S6D1121.SetBounds(x,y, x + width - 1, y + height - 1)
      do       
         data.Byte0 = SD.ReadByte 
         data.Byte1 = SD.ReadByte
         Tft.S6D1121.WriteData(data)
      loop Until SD.EOF  
      SD.Close 
   end if
end function

' program entry point...
Sub Main()

   Tft.Clear 
   Tft.SetFont(Fixed) 

   ' initialise the SD card...
   If SD.Init <> errOK Then 
      Tft.WriteAt(10,10,"Failed to initialise")

   ' now read the data...
   else   
      while true 
         SetBitmap(0,0,"sunset.img")
         delayms(1000)
         SetBitmap(0,0,"bfly.img")  
         delayms(1000)    
         SetBitmap(0,0,"bird.img")  
         delayms(1000) 
         SetBitmap(0,0,"puffin.img")  
         delayms(1000) 
         SetBitmap(0,0,"tiger.img")  
         delayms(1000)
      end while
   end if   
End Sub

' disable UART1 on pins D0 and D1...
sub OnStartup() Handles PIC.OnStartup
   RPINR18 = RPINR18 or &H001F
   RPOR2 = RPOR2 and &HE0FF    
end sub