Ported Control Serial Display Via Commands. Uses Highest Speed BAUD Rate Possible. You can DRAW,TYPE Create Menus or whatever you like just by communicating with the mbed over serial connection. I did this a while back however Ian Uploaded most of the files i published a while back to his account.
Everything should be working. If not start a discussion and i'll help you asap.
Here is some VB.NET code to help you get started playing with the tft screen through serial. This code will create a menu based graphics which you can select the menu on the left of the screen You can create your own in menu graphics and items however you like, and modify the code to make the mbed do anything you like from inside the windows vb.net application, All you will need is 6 buttons on the form.
VB.NET CODE
Imports System.Threading Public Class Form1 dim com_port as string = "COM6" 'CHANGE THIS TO YOUR MBED COM PORT NUMBER 'Load/Close Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing SerialPort1.WriteLine("fill,255,255,255") SerialPort1.Close() Try End Catch Thread.EndThreadAffinity() End Try End Sub Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load SerialPort1.PortName = com_port SerialPort1.Open() SerialPort1.WriteLine("fill,255,255,255") Thread.Sleep(2000) 'Required SerialPort1.WriteLine("rot,3") init_menu() End Sub 'Create TFT Graphics Public Sub write_text(ByVal msg As String, ByVal x As Integer, ByVal y As Integer, ByVal size As Integer, ByVal rgb As String) Dim send_string As String = "text," + msg + "," + x.ToString + "," + y.ToString + "," + size.ToString + "," + rgb SerialPort1.WriteLine(send_string) Thread.Sleep(40) End Sub Public Sub create_rect(ByVal sx As Integer, ByVal sy As Integer, ByVal ex As Integer, ByVal ey As Integer, ByVal rgb As String) Dim send_string As String = "rect," + sx.ToString + "," + sy.ToString + "," + ex.ToString + "," + ey.ToString + "," + rgb SerialPort1.WriteLine(send_string) Thread.Sleep(60) End Sub Public Sub create_fillrect(ByVal sx As Integer, ByVal sy As Integer, ByVal ex As Integer, ByVal ey As Integer, ByVal rgb As String) Dim send_string As String = "frect," + sx.ToString + "," + sy.ToString + "," + ex.ToString + "," + ey.ToString + "," + rgb SerialPort1.WriteLine(send_string) Thread.Sleep(60) End Sub Public Sub create_line(ByVal sx As Integer, ByVal sy As Integer, ByVal ex As Integer, ByVal ey As Integer, ByVal rgb As String) Dim send_string As String = "dline," + sx.ToString + "," + sy.ToString + "," + ex.ToString + "," + ey.ToString + "," + rgb SerialPort1.WriteLine(send_string) Thread.Sleep(60) End Sub Public Sub create_circle(ByVal x As Integer, ByVal y As Integer, ByVal size As Integer, ByVal rgb As String) Dim send_string As String = "circle," + x.ToString + "," + y.ToString + "," + size.ToString + "," + rgb SerialPort1.WriteLine(send_string) Thread.Sleep(60) End Sub 'draw main menu UI Public Sub init_menu() SerialPort1.WriteLine("rot,3") write_text("TFT_PANEL", 100, 13, 2, "200,0,0") create_line(80, 40, 320, 40, "255,0,0") 'Boarder Horizontal create_line(80, 40, 80, 240, "255,0,0") 'Boarder Vertical create_fillrect(0, 0, 80, 40, "100,100,100") 'MENU 1 write_text("Welcome", 12, 17, 1, "0,0,0") create_fillrect(0, 40, 80, 40, "100,100,100") 'MENU 2 write_text("Menu_1", 15, 57, 1, "0,0,0") create_fillrect(0, 80, 80, 40, "100,100,100") 'MENU 3 write_text("Menu_2", 15, 97, 1, "0,0,0") create_fillrect(0, 120, 80, 40, "100,100,100") 'MENU 4 write_text("Menu_3", 15, 137, 1, "0,0,0") create_fillrect(0, 160, 80, 40, "100,100,100") 'MENU 5 write_text("Menu_4", 15, 177, 1, "0,0,0") create_fillrect(0, 200, 80, 40, "100,100,100") 'MENU 6 write_text("Menu_5", 15, 217, 1, "0,0,0") 'Select Top Menu c_menu(0) End Sub 'Unselect previous selected menu tab Public Sub unselect() If last_selected = 0 Then create_fillrect(0, 0, 80, 40, "100,100,100") 'MAIN MENU write_text("Welcome", 12, 17, 1, "0,0,0") End If If last_selected = 1 Then create_fillrect(0, 40, 80, 40, "100,100,100") 'MENU 2 write_text("Menu_1", 15, 57, 1, "0,0,0") End If If last_selected = 2 Then create_fillrect(0, 80, 80, 40, "100,100,100") 'MENU 3 write_text("Menu_2", 15, 97, 1, "0,0,0") End If If last_selected = 3 Then create_fillrect(0, 120, 80, 40, "100,100,100") 'MENU 4 write_text("Menu_3", 15, 137, 1, "0,0,0") End If If last_selected = 4 Then create_fillrect(0, 160, 80, 40, "100,100,100") 'MENU 5 write_text("Menu_4", 15, 177, 1, "0,0,0") End If If last_selected = 5 Then create_fillrect(0, 200, 80, 40, "100,100,100") 'MENU 6 write_text("Menu_5", 15, 217, 1, "0,0,0") End If End Sub 'Select Menu Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click c_menu(0) End Sub Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click c_menu(1) End Sub Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click c_menu(2) End Sub Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click c_menu(3) End Sub Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click c_menu(4) End Sub Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click c_menu(5) End Sub 'SELECT MENU GRAPHICS! Dim last_selected As Integer Public Sub c_menu(ByVal menu As Integer) unselect() If menu = 0 Then last_selected = 0 create_rect(0, 0, 80, 40, "255,255,255") write_text("Welcome", 12, 17, 1, "255,255,255") '/IN MENU GRAPHICS create_fillrect(81, 41, 320, 240, "200,200,200") Thread.Sleep(850) 'Required write_text("Welcome_Panel_Menu", 90, 50, 1, "255,0,0") write_text("This_Is_A_Welcome_Panel", 90, 70, 1, "255,0,0") write_text("Menus_Can_Be_Opened_On_Left", 90, 80, 1, "255,0,0") create_circle(100, 100, 5, "255,0,0") End If If menu = 1 Then last_selected = 1 create_rect(0, 40, 80, 40, "255,255,255") write_text("Menu_1", 15, 57, 1, "255,255,255") '/IN MENU GRAPHICS create_fillrect(81, 41, 320, 240, "200,200,200") Thread.Sleep(850) 'Required write_text("Menu_1", 90, 50, 1, "255,0,0") write_text("THIS_IS_THE_FIRST_MENU", 90, 70, 1, "255,0,0") write_text("There_are_more_menus_ahead...", 90, 80, 1, "255,0,0") End If If menu = 2 Then last_selected = 2 create_rect(0, 80, 80, 40, "255,255,255") 'MENU 3 write_text("Menu_2", 15, 97, 1, "255,255,255") '/IN MENU GRAPHICS create_fillrect(81, 41, 320, 240, "200,200,200") Thread.Sleep(850) 'Required write_text("Menu_2", 90, 50, 1, "255,0,0") write_text("THIS_IS_THE_SECOND_MENU", 90, 70, 1, "255,0,0") write_text("There_are_more_menus_ahead...", 90, 80, 1, "255,0,0") End If If menu = 3 Then last_selected = 3 create_rect(0, 120, 80, 40, "255,255,255") 'MENU 3 write_text("Menu_3", 15, 137, 1, "255,255,255") '/IN MENU GRAPHICS create_fillrect(81, 41, 320, 240, "200,200,200") Thread.Sleep(850) 'Required write_text("Menu_3", 90, 50, 1, "255,0,0") write_text("THIS_IS_THE_THIRD_MENU", 90, 70, 1, "255,0,0") write_text("There_are_more_menus_ahead...", 90, 80, 1, "255,0,0") End If If menu = 4 Then last_selected = 4 create_rect(0, 160, 80, 40, "255,255,255") 'MENU 4 write_text("Menu_4", 15, 177, 1, "255,255,255") '/IN MENU GRAPHICS create_fillrect(81, 41, 320, 240, "200,200,200") Thread.Sleep(850) 'Required write_text("Menu_4", 90, 50, 1, "255,0,0") write_text("THIS_IS_THE_FOURTH_MENU", 90, 70, 1, "255,0,0") write_text("There_are_more_menus_ahead...", 90, 80, 1, "255,0,0") End If If menu = 5 Then last_selected = 5 create_rect(0, 200, 80, 40, "255,255,255") 'MENU 5 write_text("Menu_5", 15, 217, 1, "255,255,255") '/IN MENU GRAPHICS create_fillrect(81, 41, 320, 240, "200,200,200") Thread.Sleep(850) 'Required write_text("Menu_5", 90, 50, 1, "255,0,0") write_text("THIS_IS_THE_FIFTH_MENU", 90, 70, 1, "255,0,0") write_text("There_are_NO_menus_ahead...", 90, 80, 1, "255,0,0") End If End Sub End Class
Revision 1:993a4757891d, committed 2014-08-28
- Comitter:
- Elitism
- Date:
- Thu Aug 28 18:34:10 2014 +0000
- Parent:
- 0:d67893e6f32f
- Commit message:
- Added/modified info
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r d67893e6f32f -r 993a4757891d main.cpp --- a/main.cpp Thu Aug 28 17:29:23 2014 +0000 +++ b/main.cpp Thu Aug 28 18:34:10 2014 +0000 @@ -1,9 +1,8 @@ -/*Ported From Adafruit with modifications*/ - +//This code is not ported :) #include "ILI9340_Driver.h" -//(mosi,miso,sck,cs,rst,d/c) +//(mosi,miso,sck,cs,rst,d/c) Create Display Object. ILI9340_Display tft = ILI9340_Display(p5, p6, p7, p24, p25, p26); //USB Serial - Onboard USB (Requires USB Serial Driver): https://mbed.org/media/downloads/drivers/mbedWinSerial_16466.exe @@ -36,9 +35,11 @@ tft.DrawRect(atoi(pFields[1]),atoi(pFields[2]),atoi(pFields[3]),atoi(pFields[4]),uint16_t(tft.Colour565(atoi(pFields[5]), atoi(pFields[6]), atoi(pFields[7])))); } if (strcmp("frect", pFields[0]) == 0) { + //X,Y,X,Y,R,G,B tft.FillRect(atoi(pFields[1]), atoi(pFields[2]), atoi(pFields[3]), atoi(pFields[4]), uint16_t(tft.Colour565(atoi(pFields[5]), atoi(pFields[6]), atoi(pFields[7])))); } if (strcmp("dline", pFields[0]) == 0) { + //X,Y,X,Y,R,G,B tft.DrawLine(atoi(pFields[1]), atoi(pFields[2]), atoi(pFields[3]), atoi(pFields[4]), uint16_t(tft.Colour565(atoi(pFields[5]), atoi(pFields[6]), atoi(pFields[7])))); } if (strcmp("circle", pFields[0]) == 0) { @@ -55,7 +56,13 @@ } if (strcmp("text", pFields[0]) == 0) { //text,String,X,Y,Size,Color - int i = 0; while(pFields[1][i] != 0){if(pFields[1][i] == '_'){pFields[1][i] = ' ';} i++;}//Replace Char In String (For Spaces) + int i = 0; + while(pFields[1][i] != 0) { + if(pFields[1][i] == '_') { + pFields[1][i] = ' '; //Replace Char In String (For Spaces) + } + i++; + } tft.DrawString(pFields[1], atoi(pFields[2]), atoi(pFields[3]), atoi(pFields[4]), uint16_t(tft.Colour565(atoi(pFields[5]), atoi(pFields[6]), atoi(pFields[7])))); } if (strcmp("rot", pFields[0]) == 0) { @@ -65,10 +72,11 @@ int main(int argc, char* argv[]) { + //Init display on reset/power up ILI9340_Display tft = ILI9340_Display(p5, p6, p7, p24, p25, p26); tft.DispInit(); tft.FillScreen(ILI9340_WHITE); - /////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////////// //Serial String Parse Commands Example // // command txt vector font_size R G B @@ -80,9 +88,10 @@ //These commands are sent from serial to the MBED //You can easily work out the other commands by looking above and reading //the ones i showed examples for above - //////////////////////////////////////////////////////////////////////////// + //Note: When command (text), make sure you seperate each word with a _ character + ///////////////////////////////////////////////////////////////////////////////// serial.baud(921600); - char buf[40]; + char buf[100]; //change this if you are sending a larger string to the mbed via serial. while (1) { serial.scanf("%s", buf); ParseCommands(buf, pFields, NFIELDS, ",");