Here is the new code - d'dnt want to upload a new PPT here, as it still says "ILI9341" - (could you make a variant with a more generic name (i.e. "tft" instead("ILI9341) and without instruction how to connect etc..???)
Dim txt, ty1 As Integer
Dim displayWidth
Dim displayHeight
Dim SF As Double
Public Sub Create_ILI9341_t3()
' Edit these values:
displayDiagonalInch = 3.5 'inch
displayWidth = 480 'pixel
displayHeight = 320 'pixel
' ----------------------------------
Dim sw As Double
Dim diagPix As Double
Dim objApp As Object
Dim objSheet As Object
Dim fs As Object
Dim TheFile As Object
Dim Color1 As Long
Dim Color2 As Long
Dim Text As String
Dim Shp As Shape
Dim Sld As Slide
Dim objSlide As Object
Dim x1, y1, x2, y2, x3, y3, r1, tx1, ty1 As Integer
Dim Top, Left, Width, Height, LineWidth, Radius As Integer
Dim Path, FileName As String
Dim i, j, hh, ll, s As Integer
Dim ButtonText() As String
Dim Buttonsheet() As Integer
Set objApp = GetObject(, "powerpoint.application")
Set objPres = objApp.ActivePresentation
Set fs = CreateObject("Scripting.FileSystemObject")
diagPix = Sqr(displayWidth * displayWidth + displayHeight * displayHeight)
sw = displayWidth / diagPix * displayDiagonalInch * 72
SF = (displayWidth - 1) / sw
objPres.PageSetup.SlideWidth = sw
objPres.PageSetup.SlideHeight = displayHeight / diagPix * displayDiagonalInch * 72
FileName = "ILI9341_Screens"
Path = objPres.Path
If Right(Path, 1) <> "\" Then
Path = Path & "\" & FileName & ".ino"
Else
Path = Path & FileName
End If
Set TheFile = fs.CreateTextFile(Path, True)
' write header block
TheFile.WriteLine ("/*")
TheFile.WriteLine ("This code was automatically generated from graphic elements in a PowerPoint presentation")
TheFile.WriteLine ("and for a Teensy MCU, and a display with ILI9341 driver")
TheFile.WriteLine ("")
TheFile.WriteLine ("Autogenerate code written by Kris Kasprzak [email protected]")
TheFile.WriteLine ("Use this code without warranty")
TheFile.WriteLine ("")
TheFile.WriteLine ("Rev Date Author Desc")
TheFile.WriteLine ("1.0 06/06/2020 Kasprzak Initial code")
TheFile.WriteLine ("")
TheFile.WriteLine ("Connections:")
TheFile.WriteLine ("Teensy Display")
TheFile.WriteLine ("3v3 Vcc")
TheFile.WriteLine ("GND GND")
TheFile.WriteLine ("7 LED (can be 3v3)")
TheFile.WriteLine ("8 RST (can be 3v3)")
TheFile.WriteLine ("9 DC")
TheFile.WriteLine ("10 CS")
TheFile.WriteLine ("11 MOSI")
TheFile.WriteLine ("12 MISO")
TheFile.WriteLine ("11 SCK")
TheFile.WriteLine ("")
TheFile.WriteLine ("Notes")
TheFile.WriteLine ("1. To use SD card replace Resistors 1,2,3 with 0 ohm")
TheFile.WriteLine ("2. Solder J1 closed")
TheFile.WriteLine ("*/")
' write includes
TheFile.WriteLine ("")
TheFile.WriteLine ("// You will need to include the appropriate .h files for the fonts")
TheFile.WriteLine ("// This example useds a combination of the stardard fonts that comes with the ILI9341_t3 and")
TheFile.WriteLine ("// the custom fonts that come with ILI9341_Fonts library.")
TheFile.WriteLine ("")
TheFile.WriteLine ("#include <SPI.h>")
TheFile.WriteLine ("#include <ILI9341_t3.h>")
TheFile.WriteLine ("#include <font_ArialBold.h>")
TheFile.WriteLine ("#include <font_ArialItalic.h>")
TheFile.WriteLine ("#include <font_ArialBoldItalic.h>")
TheFile.WriteLine ("#include <font_Arial.h>")
TheFile.WriteLine ("")
' write #defines
TheFile.WriteLine ("#define PIN_LCD 7")
TheFile.WriteLine ("#define PIN_RST 8")
TheFile.WriteLine ("#define PIN_DC 9")
TheFile.WriteLine ("#define PIN_CS 10")
TheFile.WriteLine ("")
TheFile.WriteLine ("")
' create display and DS objects
TheFile.WriteLine ("ILI9341_t3 Display = ILI9341_t3(PIN_CS, PIN_DC, PIN_RST);")
TheFile.WriteLine ("")
' if there are any rounded rectangles, consider those buttons
' create the objects
Text = "// Rounded rectangles will be turned into Adafruit buttons"
TheFile.WriteLine (Text)
Text = "// add code for touch screen processing"
TheFile.WriteLine (Text)
TheFile.WriteLine ("")
i = 1
BtnCount = 0
HasButtons = False
For s = 2 To objPres.Slides.Count
Set Sld = objPres.Slides(s)
For Each Shp In Sld.Shapes
If Shp.Type = msoAutoShape Then
If Shp.AutoShapeType = msoShapeRoundedRectangle Then
' create a button
HasButtons = True
BtnCount = BtnCount + 1
Text = "Adafruit_GFX_Button Button" & BtnCount & ";"
TheFile.WriteLine (Text)
ReDim Preserve ButtonText(BtnCount) As String
ReDim Preserve Buttonsheet(BtnCount) As Integer
Left = Round(Shp.Left * SF)
Top = Round(Shp.Top * SF)
Width = Round(Shp.Width * SF)
Height = Round(Shp.Height * SF)
ColorBorder = 65536
' adafruit libs centers the buttons
Left = Round(Left + (Width / 2))
Top = Round(Top + (Height / 2))
ColorText = Color24to16(Shp.TextFrame.TextRange.Font.Color)
ColorBTN = Color24to16(Shp.Fill.ForeColor.RGB)
If Shp.Line.Visible = msoTrue Then
ColorBorder = Color24to16(Shp.Line.ForeColor.RGB)
End If
BtnText = Shp.TextEffect.Text
Text = "Button" & BtnCount & ".initButton(&Display," & Left & ", " & Top & ", " & Width & ", " & Height _
& "," & ColorBorder & ", " & ColorBTN & ", " & ColorText & ", """ & BtnText & """, 2);"
ButtonText(BtnCount) = Text
Buttonsheet(BtnCount) = s
End If
End If
Next
Next
TheFile.WriteLine ("")
TheFile.WriteLine ("")
' write setup
TheFile.WriteLine ("void setup(){")
TheFile.WriteLine ("")
TheFile.WriteLine ("pinMode(PIN_LCD, OUTPUT);")
TheFile.WriteLine ("")
' fire up the display
TheFile.WriteLine ("Display.begin();")
TheFile.WriteLine ("delay(100);")
TheFile.WriteLine ("")
TheFile.WriteLine ("digitalWrite(PIN_LCD, HIGH);")
TheFile.WriteLine ("")
' get orientation
h = objApp.ActivePresentation.SlideMaster.Height
w = objApp.ActivePresentation.SlideMaster.Width
If h > w Then
TheFile.WriteLine ("// use 0 or 2 for portriat mode")
TheFile.WriteLine ("// you will have to experiment as displays are different")
TheFile.WriteLine ("Display.setRotation(2);")
Else
TheFile.WriteLine ("// use 1 or 3 for landscape mode")
TheFile.WriteLine ("// you will have to experiment as displays are different")
TheFile.WriteLine ("Display.setRotation(3);")
End If
TheFile.WriteLine ("")
If HasButtons = True Then
For i = 1 To BtnCount
TheFile.WriteLine (ButtonText(i))
Next
End If
TheFile.WriteLine ("")
TheFile.WriteLine ("}")
TheFile.WriteLine ("")
' write loop
TheFile.WriteLine ("void loop(){")
TheFile.WriteLine ("")
s = 0
For s = 2 To objPres.Slides.Count
TheFile.WriteLine ("")
Text = "// function call for Screen" & s - 1
TheFile.WriteLine (Text)
Text = "Screen" & s - 1
TheFile.WriteLine (Text & "();")
If objPres.Slides.Count = 2 Then
TheFile.WriteLine ("while(1){}")
Else
TheFile.WriteLine ("delay(5000);")
End If
TheFile.WriteLine ("")
Next
TheFile.WriteLine ("}")
For s = 2 To objPres.Slides.Count
Set Sld = objPres.Slides(s)
TheFile.WriteLine ("")
Text = "void Screen" & s - 1
TheFile.WriteLine (Text & "(){")
TheFile.WriteLine ("")
Set objSlide = Sld
TheFile.WriteLine ("")
' set back color
If objSlide.Background.Fill.Type = msoFillGradient Then
TheFile.WriteLine ("// note displays handle rotations differently so you may have to swap fillScreenVGradient for fillScreenHGradient")
If objSlide.Background.Fill.GradientStyle = msoGradientHorizontal Then
Color1 = Color24to16(objSlide.Background.Fill.GradientStops(1).Color.RGB)
Color2 = Color24to16(objSlide.Background.Fill.GradientStops(2).Color.RGB)
Text = "Display.fillScreenVGradient(" & Color1 & ", " & Color2 & ");"
TheFile.WriteLine (Text)
ElseIf objSlide.Background.Fill.GradientStyle = msoGradientVertical Then
Color1 = Color24to16(objSlide.Background.Fill.GradientStops(1).Color.RGB)
Color2 = Color24to16(objSlide.Background.Fill.GradientStops(2).Color.RGB)
Text = "Display.fillScreenHGradient(" & Color1 & ", " & Color2 & ");"
TheFile.WriteLine (Text)
End If
Else
Color1 = Color24to16(objSlide.Background.Fill.ForeColor.RGB)
Text = "Display.fillScreen(" & Color1 & ");"
TheFile.WriteLine (Text)
End If
TheFile.WriteLine ("")
For Each Shp In objSlide.Shapes
' get lines
If Shp.Type = msoLine Then
' special case a thick line
LineWeight = 0
LineWidth = Shp.Line.Weight
If LineWidth < 1 Then
LineWidth = 1
End If
If LineWidth > 1 And Shp.Height = 0 Then
' draw a filled rectangle
Color1 = Color24to16(Shp.Line.ForeColor.RGB)
Left = Round(Shp.Left * SF)
Top = Round(Shp.Top * SF)
Width = Round(Shp.Width * SF)
Height = Round(Shp.Line.Weight * SF)
Text = "Display.fillRect(" & Left & ", " & Top & ", " & Width & ", " & Height & ", " & Color1 & ");"
TheFile.WriteLine (Text)
ElseIf LineWidth > 1 And Shp.Width = 0 Then
' draw a filled rectangle
Color1 = Color24to16(Shp.Line.ForeColor.RGB)
Left = Round(Shp.Left * SF)
Top = Round(Shp.Top * SF)
Width = Round(Shp.Line.Weight * SF)
Height = Round(Shp.Height * SF)
Text = "Display.fillRect(" & Left & ", " & Top & ", " & Width & ", " & Height & ", " & Color1 & ");"
TheFile.WriteLine (Text)
Else
Color1 = Color24to16(Shp.Line.ForeColor.RGB)
Left = Round(Shp.Left * SF)
Top = Round(Shp.Top * SF)
Width = Round(Shp.Width * SF)
Height = Round(Shp.Height * SF)
Text = "Display.drawLine(" & Left & ", " & Top & ", " & Width & ", " & Height & ", " & Color1 & ");"
TheFile.WriteLine (Text)
End If
End If
If Shp.Type = msoAutoShape Then
LineWeight = 0
If Shp.Line.Visible = msoTrue Then
LineWeight = Round(Shp.Line.Weight * SF)
If LineWeight < 1 Then
LineWeight = 1
End If
End If
' test for rectangle
If Shp.AutoShapeType = msoShapeRectangle Then
Color1 = Color24to16(Shp.Fill.ForeColor.RGB)
Left = Round(Shp.Left * SF)
Top = Round(Shp.Top * SF)
Width = Round(Shp.Width * SF)
Height = Round(Shp.Height * SF)
Text = "// " & Shp.Name
TheFile.WriteLine (Text)
' need to test and code for filled rect and gradient fill
If Shp.Fill.Type = msoFillSolid Then
If LineWeight > 0 Then
' it has a border
Color2 = Color24to16(Shp.Line.ForeColor.RGB)
' make a rectangl the color of the border, then later paint an inner rect offset by the linewidth
Text = "Display.fillRect(" & Left & ", " & Top & ", " & Width & ", " & Height & ", " & Color1 & ");"
TheFile.WriteLine (Text)
End If
Text = "Display.fillRect(" & Left + LineWeight & ", " & Top + LineWeight & ", " & Width - (2 * LineWeight) & ", " & Height - (2 * LineWeight) & ", " & Color1 & "); // w=" & Shp.Width
TheFile.WriteLine (Text)
ElseIf Shp.Fill.Type = msoFillGradient Then
If LineWeight > 0 Then
' it has a border
Color1 = Color24to16(Shp.Line.ForeColor.RGB)
Text = "Display.fillRect(" & Left & ", " & Top & ", " & Width & ", " & Height & ", " & Color1 & ");"
TheFile.WriteLine (Text)
End If
TheFile.WriteLine ("// note displays handle rotations differently so you may have to swap fillRectHGradient for fillRectVGradient")
If Shp.Fill.GradientStyle = msoGradientHorizontal Then
Color1 = Color24to16(Shp.Fill.GradientStops(1).Color.RGB)
Color2 = Color24to16(Shp.Fill.GradientStops(2).Color.RGB)
Text = "Display.fillRectVGradient(" & Left + LineWeight & ", " & Top + LineWeight & ", " & Width - (2 * LineWeight) & ", " & Height - (2 * LineWeight) & ", " & Color1 & ", " & Color2 & ");"
TheFile.WriteLine (Text)
Else
Color1 = Color24to16(Shp.Fill.GradientStops(1).Color.RGB)
Color2 = Color24to16(Shp.Fill.GradientStops(2).Color.RGB)
Text = "Display.fillRectHGradient(" & Left + LineWeight & ", " & Top + LineWeight & ", " & Width - (2 * LineWeight) & ", " & Height - (2 * LineWeight) & ", " & Color1 & ", " & Color2 & ");"
TheFile.WriteLine (Text)
End If
Else
Text = "Display.drawRect(" & Left & ", " & y1 & ", " & x2 & ", " & y2 & ", " & Color1 & ");"
TheFile.WriteLine (Text)
End If
' does it have text?
If Len(Shp.TextFrame2.TextRange.Text) > 0 Then
DrawText Shp, TheFile
End If
' test for circle
ElseIf Shp.AutoShapeType = msoShapeOval Then
' if user got it close lets make it a circle
Color1 = Color24to16(Shp.Fill.ForeColor.RGB)
Left = Round((Shp.Left * SF) + (Shp.Width * SF) / 2)
Top = Round((Shp.Top * SF) + (Shp.Width * SF) / 2)
Radius = Round((Shp.Width * SF) / 2)
Text = "// " & Shp.Name
TheFile.WriteLine (Text)
' need to test and code for filled rect and gradient fill
If Shp.Fill.Type = msoFillSolid Then
If LineWeight > 0 Then
' it has a border
Color2 = Color24to16(Shp.Line.ForeColor.RGB)
Text = "Display.fillCircle(" & Left & ", " & Top & ", " & Radius & ", " & Color2 & ");"
TheFile.WriteLine (Text)
End If
Text = "Display.fillCircle(" & Left & ", " & Top & ", " & Radius - LineWidth & ", " & Color1 & ");"
TheFile.WriteLine (Text)
Else
Text = "Display.fillCircle(" & Left & ", " & Top & ", " & Radius & ", " & Color2 & ");"
TheFile.WriteLine (Text)
End If
' does it have text?
If Len(Shp.TextFrame2.TextRange.Text) > 0 Then
DrawText Shp, TheFile
End If
' get triangles
ElseIf Shp.AutoShapeType = msoShapeIsoscelesTriangle Then
' if user got it close lets make it a circle
Color1 = Color24to16(Shp.Fill.ForeColor.RGB)
x1 = Round(Shp.Left * SF)
y1 = Round((Shp.Top + Shp.Height) * SF)
x2 = Round((Shp.Width + Shp.Left) * SF)
y2 = Round((Shp.Top + Shp.Height) * SF)
x3 = Round((Shp.Left * SF) + (Shp.Width * SF) / 2)
y3 = Round(Shp.Top * SF)
Text = "// " & Shp.Name
TheFile.WriteLine (Text)
' need to test and code for filled rect and gradient fill
If Shp.Fill.Type = msoFillSolid Then
Text = "Display.fillTriangle(" & x1 & ", " & y1 & ", " & x2 & ", " & y2 & ", " & x3 & ", " & y3 & ", " & Color1 & ");"
TheFile.WriteLine (Text)
If LineWeight > 0 Then
' it has a border
Color1 = Color24to16(Shp.Line.ForeColor.RGB)
Text = "Display.drawTriangle(" & x1 & ", " & y1 & ", " & x2 & ", " & y2 & ", " & x3 & ", " & y3 & ", " & Color1 & ");"
TheFile.WriteLine (Text)
End If
Else
Text = "Display.drawTriangle(" & x1 & ", " & y1 & ", " & x2 & ", " & y2 & ", " & x3 & ", " & y3 & ", " & Color1 & ");"
TheFile.WriteLine (Text)
End If
' does it have text?
If Len(Shp.TextFrame2.TextRange.Text) > 0 Then
DrawText Shp, TheFile
End If
End If
' test for text box
ElseIf Shp.Type = msoTextBox Then
LineWeight = 0
If Shp.Line.Visible = msoTrue Then
LineWeight = Round(Shp.Line.Weight * SF)
If LineWeight < 1 Then
LineWeight = 1
End If
End If
Left = Round(Shp.Left * SF)
Top = Round(Shp.Top * SF)
Width = Round(Shp.Width * SF)
Height = Round(Shp.Height * SF)
Text = "// " & Shp.Name
TheFile.WriteLine (Text)
' paint a border if it has one
If LineWeight > 0 Then
' it has a border
Color1 = Color24to16(Shp.Line.ForeColor.RGB)
Text = "Display.drawRect(" & Left & ", " & Top & ", " & Width & ", " & Height & ", " & Color1 & ");"
TheFile.WriteLine (Text)
End If
' first is it filled?
If Shp.Fill.Visible = msoTrue Then
Color1 = Color24to16(Shp.Fill.ForeColor.RGB)
' need to test and code for filled rect and gradient fill
If Shp.Fill.Type = msoFillSolid Then
Text = "Display.fillRect(" & Left + LineWeight & ", " & Top + LineWeight & ", " & Width - (2 * LineWeight) & ", " & Height - (2 * LineWeight) & ", " & Color1 & ");"
TheFile.WriteLine (Text)
End If
ElseIf Shp.Fill.Type = msoFillGradient Then
TheFile.WriteLine ("// note displays handle rotations differently so you may have to swap fillRectHGradient for fillRectVGradient")
If Shp.Fill.GradientStyle = msoGradientHorizontal Then
Color1 = Color24to16(Shp.Fill.GradientStops(1).Color.RGB)
Color2 = Color24to16(Shp.Fill.GradientStops(2).Color.RGB)
Text = "Display.fillRectHGradient(" & Left + LineWeight & ", " & Top + LineWeight & ", " & Width - (2 * LineWeight) & ", " & Height - (2 * LineWeight) & ", " & Color1 & ", " & Color2 & ");"
TheFile.WriteLine (Text)
End If
If Shp.Fill.GradientStyle = msoGradientVertical Then
Color1 = Color24to16(Shp.Fill.GradientStops(1).Color.RGB)
Color2 = Color24to16(Shp.Fill.GradientStops(2).Color.RGB)
Text = "Display.fillRectVGradient(" & Left + LineWeight & ", " & Top + LineWeight & ", " & Width - (2 * LineWeight) & ", " & Height - (2 * LineWeight) & ", " & Color1 & ", " & Color2 & ");"
TheFile.WriteLine (Text)
End If
End If
' now we can draw text
DrawText Shp, TheFile
ElseIf Shp.Type = msoTable Then
Color1 = Color24to16(Shp.Table.Rows(1).Cells(1).Borders(ppBorderTop).ForeColor) ' border color
Color2 = 0 ' text color
Color3 = Color24to16(Shp.Fill.BackColor.RGB) 'fill color
Color4 = 0 ' cell color
Left = Round(Shp.Left * SF)
Top = Round(Shp.Top * SF)
Width = Round(Shp.Width * SF)
Height = Round(Shp.Height * SF)
Text = "// " & Shp.Name
TheFile.WriteLine (Text)
' draw rows in grid
hh = 0
For i = 1 To Shp.Table.Rows.Count
' hh = Round(hh + Shp.Table.Rows(i).Height)
Text = "Display.drawFastHLine(" & Left & ", " & hh + Top & ", " & Width & ", " & Color1 & ");"
TheFile.WriteLine (Text)
ll = 0
For j = 1 To Shp.Table.Columns.Count
ww = Round(Shp.Table.Columns(j).Width * SF)
If Shp.Table.Rows(i).Cells(j).Shape.Fill.Visible = msoTrue Then
Color4 = Color24to16(Shp.Table.Rows(i).Cells(j).Shape.Fill.ForeColor.RGB)
Text = "Display.fillRect(" & Left + ll & ", " & hh + Top & ", " & Round(Shp.Table.Rows(i).Cells(j).Shape.Width * SF) & ", " & Round(Shp.Table.Rows(i).Cells(j).Shape.Height * SF) & ", " & Color4 & ");"
TheFile.WriteLine (Text)
End If
' is there text in the cell?
If Len(Shp.Table.Rows(i).Cells(j).Shape.TextFrame.TextRange.Text) > 0 Then
' we have a sub below to draw text but too many object differenes
' i could pass some args...maybe later
tx1 = Round((Shp.Left + Shp.Table.Rows(i).Cells(j).Shape.TextFrame.MarginLeft) * SF)
ty1 = Round((Shp.Top + Shp.Table.Rows(i).Cells(j).Shape.TextFrame.MarginTop + 3) * SF)
Color2 = Color24to16(Shp.Table.Rows(i).Cells(j).Shape.TextFrame.TextRange.Font.Color.RGB)
Text = "// you may want to specify the background color"
TheFile.WriteLine (Text)
Text = "// Display.setTextColor(ForeColor, BackColor);"
TheFile.WriteLine (Text)
Text = "Display.setTextColor(" & Color2 & ");"
TheFile.WriteLine (Text)
Text = "Display.setFont("
Text = Text & Shp.Table.Rows(i).Cells(j).Shape.TextFrame.TextRange.Font.Name
Text = Text & "_"
Text = Text & Shp.Table.Rows(i).Cells(j).Shape.TextFrame.TextRange.Font.Size
If Shp.Table.Rows(i).Cells(j).Shape.TextFrame.TextRange.Font.Bold = msoTrue Then
Text = Text & "_Bold"
End If
If Shp.Table.Rows(i).Cells(j).Shape.TextFrame.TextRange.Font.Italic = msoTrue Then
Text = Text & "_Italic"
End If
Text = Text & ");"
TheFile.WriteLine (Text)
Text = "Display.setCursor(" & tx1 + ll & ", " & hh + ty1 + 1 & " );"
TheFile.WriteLine (Text)
Text = "Display.print(F(""" & Shp.Table.Rows(i).Cells(j).Shape.TextFrame.TextRange.Text & """));"
TheFile.WriteLine (Text)
TheFile.WriteLine ("")
End If
ll = Round(ll + (Shp.Table.Columns(j).Width) * SF)
Next
hh = Round(hh + (Shp.Table.Rows(i).Height * SF))
Next
' draw last line
Text = "Display.drawFastHLine(" & Left & ", " & hh + Top & ", " & Width & ", " & Color1 & ");"
TheFile.WriteLine (Text)
Text = "Display.drawFastHLine(" & Left & ", " & Top & ", " & Width & ", " & Color1 & ");"
TheFile.WriteLine (Text)
' draw cols in grid
ll = 0
Text = "Display.drawFastVLine(" & ll + Left & ", " & Top & ", " & Height & ", " & Color1 & ");"
TheFile.WriteLine (Text)
For i = 1 To Shp.Table.Columns.Count
ll = Round(ll + (Shp.Table.Columns(i).Width * SF))
Text = "Display.drawFastVLine(" & ll + Left & ", " & Top & ", " & Height & ", " & Color1 & ");"
TheFile.WriteLine (Text)
Next
TheFile.WriteLine ("")
End If
Next Shp
TheFile.WriteLine ("")
' draw any button
For sss = 1 To BtnCount
If Buttonsheet(sss) = s Then
Text = "Button" & sss & ".drawButton();"
TheFile.WriteLine (Text)
End If
Next
TheFile.WriteLine ("")
TheFile.WriteLine ("}")
Next
' write closing block
TheFile.WriteLine ("/*")
TheFile.WriteLine ("End of the auto-generated code for ILI9341_t3 screens")
TheFile.WriteLine ("*/")
TheFile.Close
Beep
MsgBox "The ILI9341 code is now generated from the PowerPoint presentation.", vbApplicationModal + vbInformation, "PowerPoint to ILI9431_t3 Screen Converter"
End Sub
Function Color24to16(ByVal c As Long) As Long
' Converts RGB 24 bits to 16-bit color required by the ILI9341 driver
' i sure miss bit shifting in C
Dim r, g, b As Byte
Dim r5, g6, b5 As String
Dim temp As String
r = c Mod 256
g = c \ 256 Mod 256
b = c \ 65536 Mod 256
If r = 0 Then
r5 = "00000"
Else
r5 = CBin(r)
r5 = Format((Left(r5, 5)), "00000")
End If
If g = 0 Then
g6 = "000000"
Else
g6 = CBin(g)
g6 = Format((Left(g6, 6)), "000000")
End If
If b = 0 Then
b5 = "00000"
Else
b5 = CBin(b)
b5 = Format((Left(b5, 5)), "00000")
End If
temp = r5 & g6 & b5
Color565 = Bin2Dec(temp)
Color24to16 = Color565
End Function
Function CBin(ByVal n As Double) As String
If n = 0 Then
CBin = 0
ElseIf n > 0 Then
Dim i As Double
Dim c As Long
i = 2 ^ CLng(Log(n) / Log(2) + 0.1)
Do While i >= 1
c = Fix(n / i)
CBin = CBin & c
n = n - i * c
i = i / 2
Loop
End If
CBin = Format(CBin, "00000000")
' CBin = Right(CBin, 8)
End Function
Function Bin2Dec(sMyBin As String) As Long
Dim x As Integer
Dim iLen As Integer
iLen = Len(sMyBin) - 1
For x = 0 To iLen
Bin2Dec = Bin2Dec + _
Mid(sMyBin, iLen - x + 1, 1) * 2 ^ x
Next
End Function
Sub DrawText(Shp As Shape, TheFile As Object)
tx1 = Round((Shp.TextFrame2.TextRange.Item(1).BoundLeft + Shp.TextFrame.MarginLeft - Shp.TextFrame.MarginRight) * SF)
ty1 = Round((Shp.TextFrame2.TextRange.Item(1).BoundTop + Shp.TextFrame.MarginTop - Shp.TextFrame.MarginBottom) * SF)
Color1 = Color24to16(Shp.TextFrame.TextRange.Font.Color)
Text = "// you may want to specify the background color"
TheFile.WriteLine (Text)
Text = "// Display.setTextColor(ForeColor, BackColor);"
TheFile.WriteLine (Text)
Text = "Display.setTextColor(" & Color1 & ");"
TheFile.WriteLine (Text)
Text = "Display.setFont("
Text = Text & Shp.TextEffect.FontName
Text = Text & "_"
Text = Text & Shp.TextEffect.FontSize
If Shp.TextEffect.FontBold = msoTrue Then
Text = Text & "_Bold"
End If
If Shp.TextEffect.FontItalic = msoTrue Then
Text = Text & "_Italic"
End If
Text = Text & ");"
TheFile.WriteLine (Text)
Text = "Display.setCursor(" & tx1 & ", " & ty1 & ");"
TheFile.WriteLine (Text)
Text = "Display.print(F(""" & Shp.TextEffect.Text & """));"
TheFile.WriteLine (Text)
TheFile.WriteLine ("")
End Sub