
Imports System.Speech.Recognition
Imports System.Threading
Imports System.Globalization
Imports System.Net.Mail
Imports System.Diagnostics
Imports System.Speech
Imports System.Text.RegularExpressions









Public Class Form1

    
    Private Function isnetworkavailable()

        Return My.Computer.Network.IsAvailable()

    End Function

    ' recogniser 
    Public WithEvents recog As New SpeechRecognitionEngine()






   
   

    

   

    Private Sub Form1_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed


    End Sub

    Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing


    End Sub

    
    Function IsConnected() As Boolean


        Return My.Computer.Network.IsAvailable

    End Function




    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       


      

        SerialPort1.PortName = My.Settings.COM

        ToolStripTextBox1.Text = 30






        Me.Opacity = 0
        Timer2.Start()


        PictureBox5.Hide()




        ' Serial Port Number is Not fixed (for every machine ) as when i plug in Arduino Usb Cable it creates a virtual COM Port 
        SerialPort1.Encoding = System.Text.Encoding.Default

        If SerialPort1.IsOpen = False Then
            SerialPort1.BaudRate = 9600



            Try
                SerialPort1.Open()


            Catch ex As Exception

                MsgBox(ex.Message, , "Quanto Dynamic Lamp")

            End Try


            Try


                SerialPort1.Write(0)
            Catch ex As Exception

                MsgBox(ex.Message, , "Quanto Dynamic Lamp")


            End Try




        End If



        Dim grammarbuilder As New System.Speech.Recognition.GrammarBuilder

        Dim choices As New System.Speech.Recognition.Choices({"red", "green", "blue", "fade", "random", "white", "yellow", "off"})















        grammarbuilder.Append(choices)



        grammarbuilder.Append("color")





        Dim grammar As New System.Speech.Recognition.Grammar(grammarbuilder)





        recog.LoadGrammarAsync(grammar)


        recog.SetInputToDefaultAudioDevice()




















    End Sub



    Private Function GenerateRandomcolor()

        Dim randomred As New Random
        Dim randomgreen As New Random
        Dim randomblue As New Random


        Return 0




    End Function

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)



    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)



    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)



    End Sub

    Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs)
        Process.Start("http://www.facebook.com/saurabhorange")


    End Sub

    Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click


        If colordialog.ShowDialog() = Windows.Forms.DialogResult.OK Then







            PictureBox2.Image = My.Resources._on



            SerialPort1.Write(9)

            SerialPort1.Write(colordialog.Color.R.ToString & "," & colordialog.Color.G.ToString & "," & colordialog.Color.B.ToString)


            If CheckBox2.Checked = True Then

                Dim textsynthesiser As New System.Speech.Synthesis.SpeechSynthesizer



                textsynthesiser.SpeakAsync(" Current Color Is " & colordialog.Color.ToString)


            End If


            Label2.Text = "Lamp is On"

            Dim text As String = "Lamp Color :  " & colordialog.Color.ToString & " On " & Today.Date & "  Hour: " & TimeOfDay.Hour - 12 & " Minute : " & TimeOfDay.Minute & vbNewLine

            Dim color = System.Drawing.Color.FromArgb(colordialog.Color.R, colordialog.Color.G, colordialog.Color.B)
            PictureBox5.Show()


            PictureBox5.BackColor = color



            System.IO.File.AppendAllText(My.Application.Info.DirectoryPath & "\ledlog.txt", vbNewLine & text)

            Label3.Text = colordialog.Color.ToString

            If colordialog.Color = color.Black Then

                Label3.Text = "Color : NA"


            End If


        End If



    End Sub

    Private Sub Label2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label2.Click

    End Sub

    Private Sub PictureBox1_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox1.MouseHover



    End Sub

    Private Sub PictureBox1_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox1.MouseLeave


    End Sub

    Private Sub PictureBox2_BackgroundImageChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox2.BackgroundImageChanged



    End Sub

    Private Sub PictureBox2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox2.Click





    End Sub

    Private Sub PictureBox2_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox2.MouseHover

    End Sub

    Private Sub PictureBox2_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox2.MouseLeave


    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)





















    End Sub

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)














    End Sub

    Private Sub ABOUTToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ABOUTToolStripMenuItem.Click


        If CheckBox2.Checked = True Then

            Dim textsynthesiser As New System.Speech.Synthesis.SpeechSynthesizer

            textsynthesiser.SpeakAsync("This is Quanto Dynamic Lamp version 1.0 Please refer to documentation for further details")
        End If

        If MsgBox("Quanto Dynamic Lamp (QDL) version 1.0  " & vbNewLine & " Please refer the read me file ", MsgBoxStyle.Information, "Quanto Dynamic Lamp") = MsgBoxResult.Ok Then



        End If


    End Sub

    Private Sub NONETWORKToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NONETWORKToolStripMenuItem.Click

    End Sub

    Private Sub ToolStripComboBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripComboBox1.Click
        If Internetconnectiontimer.Enabled = False Then


            Internetconnectiontimer.Start()




        End If

    End Sub


    Private Sub CHANGECOLORToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CHANGECOLORToolStripMenuItem.Click



    End Sub



    Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
        If CheckBox1.Checked = True Then
            recog.RecognizeAsync(RecognizeMode.Multiple)




        Else

            recog.RecognizeAsyncStop()




        End If


    End Sub

    Private Sub LEDLOGToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LEDLOGToolStripMenuItem.Click




    End Sub

    Private Sub FADEToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FADEToolStripMenuItem.Click

        PictureBox2.Image = My.Resources._on
        PictureBox5.Hide()

        If CheckBox2.Checked = True Then
            Dim synth As New System.Speech.Synthesis.SpeechSynthesizer

            synth.SpeakAsync("The LAMP IS Currently Fading ")

        End If


        Dim text As String = "Lamp Started Fading On  " & Today.Date & "  Hour: " & TimeOfDay.Hour - 12 & " Minute : " & TimeOfDay.Minute & vbNewLine


        System.IO.File.AppendAllText(My.Application.Info.DirectoryPath & "\ledlog.txt", vbNewLine & text)

        SerialPort1.Write(8)





        Label3.Text = "Color : NA"
        Label2.Text = "Lamp is Fading"

    End Sub

    Private Sub PictureBox3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox3.Click
        If System.IO.File.Exists(My.Application.Info.DirectoryPath & "\ledlog.txt") Then
            Process.Start(My.Application.Info.DirectoryPath & "\ledlog.txt")

        Else
            System.IO.File.Create(My.Application.Info.DirectoryPath & "\ledlog.txt")

        End If
    End Sub

    Private Sub COMPUTERTIMEToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles COMPUTERTIMEToolStripMenuItem.Click
        Me.Hide()


        Form2.Show()

    End Sub

    Private Sub Form1_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.LostFocus

    End Sub

    Private Sub OpenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenToolStripMenuItem.Click
        If System.IO.File.Exists(My.Application.Info.DirectoryPath & "\ledlog.txt") Then
            Process.Start(My.Application.Info.DirectoryPath & "\ledlog.txt")

        Else
            System.IO.File.Create(My.Application.Info.DirectoryPath & "\ledlog.txt")

        End If

    End Sub


    Private Sub DETECTCOLORFROMIMAGEToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)




    End Sub

    Private Sub PictureBox4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


    End Sub



    Private Sub DOCUMENTATIONToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DOCUMENTATIONToolStripMenuItem.Click

        If CheckBox2.Checked = True Then
            Dim textsynthesiser As New System.Speech.Synthesis.SpeechSynthesizer


            textsynthesiser.SpeakAsync("We appreciate you are reading our documentation Thank You!")
        End If

        Process.Start(My.Application.Info.DirectoryPath & "\Read Me.txt")


    End Sub

    Private Sub RANDOMCOLORToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim random As New Random




        Dim rval = random.Next(1, 256)
        Dim gval = random.Next(1, 256)
        Dim bval = random.Next(1, 256)
        PictureBox2.Image = My.Resources._on


        Dim color1 = System.Drawing.Color.FromArgb(rval.ToString, gval.ToString, bval.ToString)

        PictureBox5.Show()

        PictureBox5.BackColor = color1


        SerialPort1.Write(9)
        Label3.Text = "Color : RGB " & rval & " " & gval & " " & bval


        SerialPort1.Write(rval.ToString & "," & gval.ToString & "," & bval.ToString)



    End Sub

    Private Sub BRIGHTNESSToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick



    End Sub

    Private Sub BLINKToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)




    End Sub

    Function EmailAddressCheck(ByVal emailAddress As String) As Boolean

        Dim pattern As String = "^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$"
        Dim emailAddressMatch As Match = Regex.Match(emailAddress, pattern)
        If emailAddressMatch.Success Then
            EmailAddressCheck = True
        Else
            EmailAddressCheck = False
        End If

    End Function

    Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
        If CheckBox2.Checked = True Then
            Dim textsynthesiser As New System.Speech.Synthesis.SpeechSynthesizer


            textsynthesiser.SpeakAsync("Please enter your Email")
        End If

        Dim input As String = ""


        Do While (input = "")


            input = InputBox("Enter the email to send Lamp History data to ")
        Loop



        Dim smtpclient As New SmtpClient
        smtpclient.Host = "smtp.gmail.com"
        smtpclient.EnableSsl = True
        smtpclient.Port = "587"



        smtpclient.Credentials = New System.Net.NetworkCredential("saurabhinorange@gmail.com", "mdsrfamily")

        Dim strmessage = System.IO.File.ReadAllText(My.Application.Info.DirectoryPath & "\ledlog.txt")



        smtpclient.Send("saurabhinorange@gmail.com", input, "Your Lamp Report", "Here is your lamp report as you requested " & strmessage)
        MsgBox("Lamp Data Sent")


    End Sub

    Private Sub Button4_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs)


    End Sub

    Private Sub RGBVALUEToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RGBVALUEToolStripMenuItem.Click

        Dim INPUT = InputBox("Enter the RGB CODE (RED , GREEN AND BLUE COMPONENT RANGING FROM 0 - 255 SEPERATED BY COMMA) ")
        If INPUT <> "" Then
            PictureBox2.Image = My.Resources._on

            SerialPort1.Write(9)
            SerialPort1.Write(INPUT)

            Label3.Text = "Color : RGB " & INPUT
            Label2.Text = "Lamp is On"



            Dim color As New Color
            color.FromArgb(INPUT)

            If CheckBox2.Checked = True Then

                Dim textsynthesiser As New System.Speech.Synthesis.SpeechSynthesizer



                textsynthesiser.SpeakAsync(" Current Color Is RGB " & INPUT)



            End If


            If INPUT = "0,0,0" Then

                Label3.Text = "Color : NA"


            End If



        End If


    End Sub

    Private Sub Label3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label3.Click

    End Sub

    Private Sub Label3_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Label3.TextChanged
        If Label3.Text.Contains("Red") Or Label3.Text.Contains("red") Or Label3.Text.Contains("green") Or _
            Label3.Text.Contains("GREEN") Or Label3.Text.Contains("blue") Or Label3.Text.Contains("BLUE") = True Then



        Else



        End If



    End Sub

    Private Sub EmailLogToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EmailLogToolStripMenuItem.Click

        BackgroundWorker1.RunWorkerAsync()






    End Sub

    Private Sub MYFACEBOOKToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub COLORPICKERToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles COLORPICKERToolStripMenuItem.Click
        PictureBox1_Click(sender, e)

    End Sub

    Private Sub INCOMINGEMAILToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub OpenToolStripMenuItem_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) Handles OpenToolStripMenuItem.MouseHover
        OpenToolStripMenuItem.ForeColor = Color.White
        OpenToolStripMenuItem.BackColor = Color.Black

    End Sub

    Private Sub TOOLSToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TOOLSToolStripMenuItem.Click

    End Sub

    Private Sub TOOLSToolStripMenuItem_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) Handles TOOLSToolStripMenuItem.MouseHover


    End Sub

    Private Sub TOOLSToolStripMenuItem_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles TOOLSToolStripMenuItem.MouseLeave

    End Sub

    Private Sub ADDTOSTARTUPToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub PrintLogToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)



    End Sub

    Private Sub PictureBox6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox6.Click
        ABOUTToolStripMenuItem_Click(sender, e)
    End Sub

    Private Sub PictureBox6_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox6.MouseHover
        PictureBox6.Image = My.Resources._21

    End Sub

    Private Sub PictureBox6_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox6.MouseLeave
        PictureBox6.Image = My.Resources.plastic_buttons

    End Sub

    Private Sub PictureBox7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox7.Click

        PictureBox2.Image = My.Resources._on





        SerialPort1.Write(1)

        If CheckBox2.Checked = True Then
            Dim synth As New System.Speech.Synthesis.SpeechSynthesizer

            synth.SpeakAsync("LAMP IS NOW ON")
        End If


        Label2.Text = "Lamp Is ON"

        Dim text As String = "Lamp Became On ( and set to default color red ) on Day : " & Today.Date & "  Hour : " & TimeOfDay.Hour - 12 & " Minute : " & TimeOfDay.Minute & vbNewLine


        System.IO.File.AppendAllText(My.Application.Info.DirectoryPath & "\ledlog.txt", vbNewLine & text)
        PictureBox5.BackColor = Color.Red
        PictureBox5.Show()

        Label3.Text = "Color : Red"


    End Sub

    Private Sub PictureBox8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox8.Click


        PictureBox2.Image = My.Resources.off


        Label2.Text = "Lamp Is OFF"
        SerialPort1.Write(0)
        If CheckBox2.Checked = True Then
            Dim synth As New System.Speech.Synthesis.SpeechSynthesizer

            synth.SpeakAsync("LAMP IS Off")
        End If


        Dim text As String = "Lamp Became Off  on Day: " & Today.Date & "  Hour: " & TimeOfDay.Hour - 12 & " Minute : " & TimeOfDay.Minute & vbNewLine


        System.IO.File.AppendAllText(My.Application.Info.DirectoryPath & "\ledlog.txt", vbNewLine & text)

        Label3.Text = "Color : NA"

        PictureBox5.Hide()


    End Sub

    Private Sub PictureBox7_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox7.MouseHover
        PictureBox7.Image = My.Resources.lighton2



    End Sub

    Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub PictureBox9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox9.Click
        SerialPort1.Write(0)


        If CheckBox2.Checked = True Then
            Dim textsynthesiser As New System.Speech.Synthesis.SpeechSynthesizer


            textsynthesiser.SpeakAsync("Good Bye!")
        End If


        Timer3.Start()



    End Sub

    Private Sub PictureBox7_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox7.MouseLeave
        PictureBox7.Image = My.Resources.lighton1

    End Sub

    Private Sub PictureBox8_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox8.MouseHover
        PictureBox8.Image = My.Resources.lightoff2

    End Sub

    Private Sub PictureBox8_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox8.MouseLeave
        PictureBox8.Image = My.Resources.lightoff1

    End Sub

    Private Sub MenuStrip1_ItemClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolStripItemClickedEventArgs) Handles MenuStrip1.ItemClicked

    End Sub

    Private Sub CheckBox2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox2.CheckedChanged



    End Sub

    Private Sub HELPToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HELPToolStripMenuItem.Click

    End Sub

    Private Sub HELPToolStripMenuItem_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) Handles HELPToolStripMenuItem.MouseHover
        HELPToolStripMenuItem.BackColor = Color.Transparent
        HELPToolStripMenuItem.BackgroundImage = My.Resources.helpmenu2


    End Sub

    Private Sub HELPToolStripMenuItem_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles HELPToolStripMenuItem.MouseLeave
        HELPToolStripMenuItem.BackgroundImage = My.Resources.helpmenu

    End Sub

    Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
        If Me.Opacity = 1 Then

            Timer2.Enabled = False


        Else
            Me.Opacity = Me.Opacity + 0.05



        End If
    End Sub

    Private Sub Timer3_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer3.Tick
        If Me.Opacity <= 0.1 Then

            Timer3.Enabled = False

            End






        Else

            Me.Opacity = Me.Opacity - 0.1




        End If
    End Sub

    Private Sub ToolStripComboBox2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripComboBox2.Click
        If ToolStripComboBox2.Text <> "" Then

            batterytimer.Start()



        End If
    End Sub

    Private Sub recog_SpeechDetected(ByVal sender As Object, ByVal e As System.Speech.Recognition.SpeechDetectedEventArgs) Handles recog.SpeechDetected



    End Sub

    Private Sub recog_SpeechRecognitionRejected(ByVal sender As Object, ByVal e As System.Speech.Recognition.SpeechRecognitionRejectedEventArgs) Handles recog.SpeechRecognitionRejected


    End Sub

    Private Sub recog_SpeechRecognized(ByVal sender As Object, ByVal e As System.Speech.Recognition.SpeechRecognizedEventArgs) Handles recog.SpeechRecognized
        Label2.Text = "Lamp is On "


        If (e.Result.Text = "red color") And e.Result.Confidence > 0.8 Then

            SerialPort1.Write(1)

            Dim text As String = "Color Changed to red on Day: " & TimeOfDay.Day & "  Hour: " & TimeOfDay.Hour - 12 & " Minute : " & TimeOfDay.Minute & vbNewLine
            PictureBox5.Show()

            PictureBox5.BackColor = Color.Red

            Label3.Text = "Color : Red "
            System.IO.File.AppendAllText(My.Application.Info.DirectoryPath & "\ledlog.txt", vbNewLine & text)

        ElseIf (e.Result.Text = "fade color") And e.Result.Confidence > 0.7 Then

            FADEToolStripMenuItem_Click(sender, e)

            PictureBox5.Hide()


        ElseIf (e.Result.Text = "random color") And e.Result.Confidence > 0.7 Then
            RandomColorToolStripMenuItem1_Click(sender, e)






        ElseIf (e.Result.Text = "yellow color") And e.Result.Confidence > 0.7 Then
            SerialPort1.Write(5)

            Label3.Text = "Color : Yellow "
            PictureBox5.Show()
            PictureBox5.BackColor = Color.Yellow

            Dim text As String = "Color Changed to Yellow on Day: " & TimeOfDay.Day & "  Hour: " & TimeOfDay.Hour - 12 & " Minute : " & TimeOfDay.Minute & vbNewLine

            System.IO.File.AppendAllText(My.Application.Info.DirectoryPath & "\ledlog.txt", vbNewLine & text)



        ElseIf (e.Result.Text = "green color") And e.Result.Confidence > 0.8 Then
            SerialPort1.Write(2)
            PictureBox5.Show()
            PictureBox5.BackColor = Color.Green

            Dim text As String = "Color Changed to green on Day: " & TimeOfDay.Day & "  Hour: " & TimeOfDay.Hour - 12 & " Minute : " & TimeOfDay.Minute & vbNewLine
            Label3.Text = "Color : Green "

            System.IO.File.AppendAllText(My.Application.Info.DirectoryPath & "\ledlog.txt", vbNewLine & text)

        ElseIf (e.Result.Text = "blue color") And e.Result.Confidence > 0.8 Then
            SerialPort1.Write(3)
            PictureBox5.Show()
            PictureBox5.BackColor = Color.Blue

            Dim text As String = "Color Changed to blue on Day: " & TimeOfDay.Day & "  Hour: " & TimeOfDay.Hour - 12 & " Minute : " & TimeOfDay.Minute & vbNewLine

            Label3.Text = "Color : Blue "
            System.IO.File.AppendAllText(My.Application.Info.DirectoryPath & "\ledlog.txt", vbNewLine & text)


        ElseIf (e.Result.Text = "white color") And e.Result.Confidence > 0.8 Then
            SerialPort1.Write(4)
            PictureBox5.Show()

            PictureBox5.BackColor = Color.White

            Dim text As String = "Color Changed to white on Day: " & TimeOfDay.Day & "  Hour: " & TimeOfDay.Hour - 12 & " Minute : " & TimeOfDay.Minute & vbNewLine


            System.IO.File.AppendAllText(My.Application.Info.DirectoryPath & "\ledlog.txt", vbNewLine & text)

            Label3.Text = "Color : White "


        ElseIf (e.Result.Text = "off color") And e.Result.Confidence > 0.8 Then
            SerialPort1.Write(0)

            PictureBox5.Hide()
            PictureBox2.Image = My.Resources.off

            Dim text As String = "Lamp became off on Day: " & TimeOfDay.Day & "  Hour: " & TimeOfDay.Hour - 12 & " Minute : " & TimeOfDay.Minute & vbNewLine
            Label3.Text = "Color : NA "
            Label2.Text = "Lamp is Off"


            System.IO.File.AppendAllText(My.Application.Info.DirectoryPath & "\ledlog.txt", vbNewLine & text)




        End If
    End Sub

    Private Sub HIDEToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HIDEToolStripMenuItem.Click
        If CheckBox2.Checked = True Then
            Dim textsynthesiser As New System.Speech.Synthesis.SpeechSynthesizer


            textsynthesiser.SpeakAsync("This Application is still running in the background! You can use voice recognition mode")
        End If
        Me.Hide()
        NotifyIcon1.Visible = True
        NotifyIcon1.ShowBalloonTip(500)

    End Sub

    Private Sub NotifyIcon1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles NotifyIcon1.Click
        Me.Show()

    End Sub

    Private Sub CHANGECOMPORTToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CHANGECOMPORTToolStripMenuItem.Click
        Dim input = InputBox("enter COM port", , "COM4")


        While (input = "")

            input = InputBox("enter COM port", , "COM4")


        End While

        My.Settings.COM = input.ToString



        My.Settings.Save()


        SerialPort1.Close()
        SerialPort1.PortName = My.Settings.COM

        Try

            SerialPort1.Open()

        Catch ex As Exception



            MsgBox(ex.Message)

        End Try


    End Sub

    Private Sub batterytimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles batterytimer.Tick

        If ToolStripComboBox2.Text <> "" Then
            Dim power As PowerStatus = SystemInformation.PowerStatus



            If power.BatteryLifePercent <= ToolStripTextBox1.Text / 10 Then




                If ToolStripComboBox2.Text = "Green" Then
                    SerialPort1.Write(2)

                ElseIf ToolStripComboBox2.Text = "Red" Then

                    SerialPort1.Write(1)

                ElseIf ToolStripComboBox2.Text = "Blue" Then



                ElseIf ToolStripComboBox2.Text = "White" Then

                ElseIf ToolStripComboBox2.Text = "yellow" Then


                End If


            End If

        End If

    End Sub

    Private Sub ToolStripTextBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripTextBox1.Click


    End Sub

    Private Sub DetectColorFromImageToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim openfile As New OpenFileDialog





        If openfile.ShowDialog() = Windows.Forms.DialogResult.OK Then
            Form4.Show()

            Form4.PictureBox1.ImageLocation = openfile.FileName



        End If
    End Sub

    Private Sub DetectColorFromImageToolStripMenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DetectColorFromImageToolStripMenuItem2.Click
        Dim openfile As New OpenFileDialog





        If openfile.ShowDialog() = Windows.Forms.DialogResult.OK Then
            Form4.Show()

            Form4.PictureBox1.ImageLocation = openfile.FileName



        End If
    End Sub

    Private Sub RandomColorToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RandomColorToolStripMenuItem1.Click
        Dim random As New Random

        If CheckBox2.Checked = True Then

            Dim textsynthesiser As New System.Speech.Synthesis.SpeechSynthesizer



            textsynthesiser.SpeakAsync(" A random color is generated")



        End If



        Dim rval = random.Next(1, 256)
        Dim gval = random.Next(1, 256)
        Dim bval = random.Next(1, 256)
        PictureBox2.Image = My.Resources._on

        Dim text As String = "A random color was generated  (" & "Color : RGB " & rval & " " & gval & " " & bval & ") on " & Today.Date & "  Hour : " & TimeOfDay.Hour - 12 & " Minute : " & TimeOfDay.Minute & vbNewLine


        System.IO.File.AppendAllText(My.Application.Info.DirectoryPath & "\ledlog.txt", vbNewLine & text)

        Dim color1 = System.Drawing.Color.FromArgb(rval.ToString, gval.ToString, bval.ToString)

        PictureBox5.Show()

        PictureBox5.BackColor = color1


        SerialPort1.Write(9)
        Label3.Text = "Color : RGB " & rval & " " & gval & " " & bval


        SerialPort1.Write(rval.ToString & "," & gval.ToString & "," & bval.ToString)
    End Sub

    Private Sub Internetconnectiontimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Internetconnectiontimer.Tick
        If ToolStripComboBox1.Text <> "None" Then

            If IsConnected() = False Then


                If ToolStripComboBox1.Text = "Red" Then

                    SerialPort1.Write(1)

                ElseIf ToolStripComboBox1.Text = "Green" Then
                    SerialPort1.Write(2)
                ElseIf ToolStripComboBox1.Text = "Blue" Then
                    SerialPort1.Write(3)

                ElseIf ToolStripComboBox1.Text = "white" Then
                    SerialPort1.Write(4)

                ElseIf ToolStripComboBox1.Text = "Yellow" Then
                    SerialPort1.Write(5)
                End If

            End If


        End If
    End Sub

    Private Sub Timer4_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer4.Tick
        If CheckBox1.Checked = True Then

            If recog.AudioState = AudioState.Speech Then

                Label1.Text = "Speech is being processed "

                PictureBox10.Visible = True


            Else
                Label1.Text = ""

                PictureBox10.Visible = False

            End If


        Else

            Label1.Text = ""

            PictureBox10.Visible = False

        End If


    End Sub
End Class
