0% found this document useful (0 votes)
12 views9 pages

Materi Komunikasi Serial Arduino VB: Form1 Object Eventargs

Uploaded by

Penaple Pen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views9 pages

Materi Komunikasi Serial Arduino VB: Form1 Object Eventargs

Uploaded by

Penaple Pen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

MATERI KOMUNIKASI SERIAL ARDUINO VB

FORM

PROGRAM VISUAL BASIC


Public Class Form1
Dim data_masuk As String
Private Sub pb_connect_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles pb_connection.Click
End Sub

Private Sub btn_connect_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btn_connect.Click
SerialPort1.BaudRate = Val(tb_baudrate.Text)
SerialPort1.PortName = tb_com.Text
Try
SerialPort1.Open()
If SerialPort1.IsOpen Then
pb_connection.BackColor = Color.LimeGreen
tim_serial.Enabled = True
End If
Catch ex As Exception
MessageBox.Show("Komunikasi gagal..", "Note")
End Try
End Sub

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


Handles MyBase.Load
End Sub

Private Sub SerialPort1_DataReceived(ByVal sender As System.Object, ByVal e As


System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
data_masuk = SerialPort1.ReadLine()
End Sub

Private Sub tim_serial_Tick(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles tim_serial.Tick
lbl_data_masuk.Text = data_masuk
End Sub

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


System.EventArgs) Handles Button1.Click
SerialPort1.Close()
pb_connection.BackColor = Color.Red
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
End
End Sub

Private Sub lbl_data_masuk_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles lbl_data_masuk.Click
End Sub
End Class

PROGRAM ARDUINO

void setup() {

Serial.begin(9600);

void loop() {

int data_random=random (0,1023);

Serial.println(data_random);

delay(100);

}
MATERI KOMUNIKASI SERIAL ARDUINO VB SAKLAR ON OFF
FORM

PROGRAM VISUAL BASIC

Public Class Form1


Dim data_masuk As String
Private Sub pb_connect_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles pb_connection.Click
End Sub

Private Sub btn_connect_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btn_connect.Click
SerialPort1.BaudRate = Val(tb_baudrate.Text)
SerialPort1.PortName = tb_com.Text
Try
SerialPort1.Open()
If SerialPort1.IsOpen Then
pb_connection.BackColor = Color.LimeGreen
tim_serial.Enabled = True
End If
Catch ex As Exception
MessageBox.Show("Komunikasi gagal..", "Note")
End Try
End Sub

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


Handles MyBase.Load
End Sub

Private Sub SerialPort1_DataReceived(ByVal sender As System.Object, ByVal e As


System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
data_masuk = SerialPort1.ReadLine()
End Sub

Private Sub tim_serial_Tick(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles tim_serial.Tick
lbl_data_masuk.Text = data_masuk
End Sub

Private Sub send_data(ByVal data_kirim As String)


If SerialPort1.IsOpen() Then
SerialPort1.Write(data_kirim + Environment.NewLine)
End If
End Sub
Private Sub btn_on_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btn_on.Click
send_data("1")
End Sub

Private Sub btn_off_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btn_off.Click
send_data("2")
End Sub

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


System.EventArgs) Handles Button1.Click
SerialPort1.Close()
pb_connection.BackColor = Color.Red
End Sub

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


System.EventArgs) Handles Button2.Click
End
End Sub
End Class

PROGRAM ARDUINO

#define lampu 13
void setup()
{
Serial.begin(9600);
pinMode(lampu,OUTPUT);
digitalWrite(lampu,LOW);
}

void loop()
{
if (Serial.available())
{
int data_masuk=Serial.parseInt();
if (data_masuk==1)
{
digitalWrite(lampu,HIGH);
}
else if (data_masuk==2)
{
digitalWrite(lampu,LOW);
}
}
int data_random=random (0,1023);
Serial.println(data_random);
delay(10);
}
MATERI MENYALAKAN LED DI ARDUINO DARI VISUAL BASIC
FORM

PROGRAM VISUAL BASIC


Imports System
Imports System.Threading
Imports System.IO.Ports
Imports System.ComponentModel
Public Class Form1
Dim myPort As Array
Delegate Sub SetTextCallback(ByVal [text] As String)
Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles ComboBox2.SelectedIndexChanged

End Sub

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


Handles MyBase.Load
myPort = IO.Ports.SerialPort.GetPortNames()
ComboBox1.Items.AddRange(myPort)
Button1.BackColor = Color.DarkGray
Button2.BackColor = Color.DarkGray

Button1.Enabled = False
Button2.Enabled = False
ComboBox2.Items.Add(9600)
ComboBox2.Items.Add(38400)
ComboBox2.Items.Add(57600)
ComboBox2.Items.Add(115200)
End Sub

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


System.EventArgs) Handles Button4.Click
End
End Sub

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


System.EventArgs) Handles Button3.Click
SerialPort1.PortName = ComboBox1.Text
SerialPort1.BaudRate = ComboBox2.Text
SerialPort1.Open()
Button3.BackColor = Color.Yellow
Button5.BackColor = Color.DarkGray
Button1.Enabled = True
Button2.Enabled = True
Button3.Enabled = False
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
SerialPort1.Write("A")
Button1.BackColor = Color.Lime
Button2.BackColor = Color.DarkGray
Button1.Enabled = False
Button2.Enabled = True
End Sub

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


System.EventArgs) Handles Button2.Click
SerialPort1.Write("a")
Button2.BackColor = Color.Red
Button1.BackColor = Color.DarkGray
Button1.Enabled = True
Button2.Enabled = False
End Sub

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button5.Click
SerialPort1.Close()
Button5.BackColor = Color.Red
Button3.BackColor = Color.DarkGray
End Sub
End Class

PROGRAM ARDUINO

#define led13 13
char val;

void setup()
{
Serial.begin(9600);
pinMode(led13,OUTPUT);
}
void loop()
{
if(Serial.available()!=0){
val=Serial.read();
Serial.print(val);

if(val=='A')
{
digitalWrite(led13,HIGH);
}
if(val=='a')
{
digitalWrite(led13,LOW);
}
}
}
MATERI MENYALAKAN LED DI ARDUINO DARI VISUAL BASIC 2

FORM

PROGRAM VISUAL BASIC


Imports System
Imports System.Threading
Imports System.IO.Ports
Imports System.ComponentModel

Public Class Form1


Dim myPort As Array
Delegate Sub SetTextCallback(ByVal [text] As String)

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


Handles MyBase.Load
myPort = IO.Ports.SerialPort.GetPortNames()
ComboBox1.Items.AddRange(myPort)
Button1.BackColor = Color.DarkGray
Button2.BackColor = Color.DarkGray
Button3.BackColor = Color.DarkGray
Button4.BackColor = Color.DarkGray
Button5.BackColor = Color.DarkGray
Button6.BackColor = Color.DarkGray
Button7.BackColor = Color.DarkGray

Button1.Enabled = False
Button2.Enabled = False
Button3.Enabled = False
Button4.Enabled = False
Button5.Enabled = False
Button6.Enabled = False

ComboBox2.Items.Add(9600)
ComboBox2.Items.Add(38400)
ComboBox2.Items.Add(57600)
ComboBox2.Items.Add(115200)

End Sub

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


System.EventArgs) Handles Button1.Click
SerialPort1.Write("A")
Button1.BackColor = Color.Lime
Button4.BackColor = Color.DarkGray
Button1.Enabled = False
Button4.Enabled = True
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
SerialPort1.Write("B")
Button2.BackColor = Color.Lime
Button5.BackColor = Color.DarkGray
Button2.Enabled = False
Button5.Enabled = True
End Sub

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


System.EventArgs) Handles Button3.Click
SerialPort1.Write("C")
Button3.BackColor = Color.Lime
Button6.BackColor = Color.DarkGray
Button3.Enabled = False
Button6.Enabled = True
End Sub

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


System.EventArgs) Handles Button4.Click
SerialPort1.Write("a")
Button4.BackColor = Color.Red
Button1.BackColor = Color.DarkGray
Button1.Enabled = True
Button4.Enabled = False

End Sub

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button5.Click
SerialPort1.Write("b")
Button5.BackColor = Color.Red
Button2.BackColor = Color.DarkGray
Button2.Enabled = True
Button5.Enabled = False
End Sub

Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button6.Click
SerialPort1.Write("c")
Button6.BackColor = Color.Red
Button3.BackColor = Color.DarkGray
Button3.Enabled = True
Button6.Enabled = False
End Sub

Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button7.Click
End
End Sub

Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button8.Click
SerialPort1.PortName = ComboBox1.Text
SerialPort1.BaudRate = ComboBox2.Text
SerialPort1.Open()

Button4.BackColor = Color.Red
Button5.BackColor = Color.Red
Button6.BackColor = Color.Red
Button7.BackColor = Color.Yellow

Button8.BackColor = Color.Lime
Button9.BackColor = Color.DarkGray
Button1.Enabled = True
Button2.Enabled = True
Button3.Enabled = True
Button4.Enabled = True
Button5.Enabled = True
Button6.Enabled = True

End Sub
Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button9.Click
SerialPort1.Close()
Button8.BackColor = Color.DarkGray
Button9.BackColor = Color.Lime

End Sub

End Class

PROGRAM ARDUINO
#define led1 5
#define led2 6
#define led3 7
char val;

void setup()
{
Serial.begin(9600);
pinMode(led1,OUTPUT);
pinMode(led2,OUTPUT);
pinMode(led3,OUTPUT);

}
void loop()
{
if(Serial.available()!=0){
val=Serial.read();
Serial.print(val);

if(val=='A'){
digitalWrite(led1,HIGH);}
if(val=='a'){
digitalWrite(led1,LOW);}

if(val=='B'){
digitalWrite(led2,HIGH);}
if(val=='b'){
digitalWrite(led2,LOW);}

if(val=='C'){
digitalWrite(led3,HIGH);}
if(val=='c'){
digitalWrite(led3,LOW);}
}}

You might also like