0% found this document useful (0 votes)
31 views

Final Mikrokontroller Interface

1) The document describes a microcontroller project by A. Muh. Hilal Basir involving code for an Arduino and Visual Basic program to control LEDs. 2) The Arduino code reads input from buttons and sends character values to control LED color changes in the Visual Basic program. 3) The Visual Basic program uses timers to change the color of oval shapes, representing LEDs, based on character values received from the Arduino.

Uploaded by

Winda Awalia
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views

Final Mikrokontroller Interface

1) The document describes a microcontroller project by A. Muh. Hilal Basir involving code for an Arduino and Visual Basic program to control LEDs. 2) The Arduino code reads input from buttons and sends character values to control LED color changes in the Visual Basic program. 3) The Visual Basic program uses timers to change the color of oval shapes, representing LEDs, based on character values received from the Arduino.

Uploaded by

Winda Awalia
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 14

FINAL MIKROKONTROLER

NAMA : A. MUH. HILAL BASIR


KELAS : 2A D3 TEKNIK ELEKTRONIKA
NIM : 323 17 015

 CODE PROGRAM 1 ARDUINO KE HMI:


const int s1=10;
const int s2=11;
const int s3=12;
const int s4=13;

char status;
void setup() {
Serial.begin(9600);
pinMode(10,INPUT);
pinMode(11,INPUT);
pinMode(12,INPUT);
pinMode(13,INPUT);
pinMode(3,OUTPUT);
pinMode(6,OUTPUT);
pinMode(7,OUTPUT);
}

void loop() {

if(digitalRead(10)==LOW){
Serial.write("5");
}
else if (digitalRead(11)==LOW){
Serial.write("6");
}
else if (digitalRead(12)==LOW){
Serial.write("7");
}
else if (digitalRead(13)==LOW){
Serial.write("8");
}

}
 CODE PROGRAM 1 HMI KE ARDUINO:
char status;
void setup() {
Serial.begin(9600);
pinMode(3,OUTPUT);
pinMode(6,OUTPUT);
pinMode(7,OUTPUT);
pinMode(10,INPUT);
pinMode(11,INPUT);
pinMode(12,INPUT);
pinMode(13,INPUT);

void loop() {

if (Serial.available()){
status = Serial.read();
}
switch (status){

case '1':

digitalWrite(4,100);
digitalWrite(6,HIGH);
digitalWrite(7,LOW);
break;
case '2':

digitalWrite(4,1);
digitalWrite(6,HIGH);
digitalWrite(7,LOW);
break;

case '3':

digitalWrite(4,HIGH);
digitalWrite(7,HIGH);
digitalWrite(6,LOW);
break;

case '4':

digitalWrite(4,HIGH);
digitalWrite(6,HIGH);
digitalWrite(7,LOW);
break;

if(digitalRead(10)==LOW){
Serial.write('5');
}
else if (digitalRead(11)==LOW){
Serial.write('6');
}

}
 CODE PROGRAM PADA VISUAL BASIC

Public Class Form1

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


Handles Button1.Click
MSComm1.Output = "1"

End Sub

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


Handles Button2.Click
MSComm1.Output = "2"

End Sub

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


Handles Button3.Click
MSComm1.Output = "3"

End Sub

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


Handles Button4.Click
MSComm1.Output = "4"

End Sub

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


Me.Load
MSComm1.PortOpen = True

End Sub

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


System.EventArgs)

End Sub

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


System.EventArgs)

End Sub

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


System.EventArgs)

End Sub

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


System.EventArgs) Handles MSComm1.OnComm, OvalShape4.BackColorChanged,
OvalShape3.BackColorChanged, OvalShape2.BackColorChanged, OvalShape1.BackColorChanged
If MSComm1.Input = "5" Then
Timer1.Enabled = True
Timer2.Enabled = False
Timer3.Enabled = False
Timer4.Enabled = False
ElseIf MSComm1.Input = "6" Then
Timer1.Enabled = False
Timer2.Enabled = True
Timer3.Enabled = False
Timer4.Enabled = False
ElseIf MSComm1.Input = "7" Then
Timer1.Enabled = False
Timer2.Enabled = False
Timer3.Enabled = True
Timer4.Enabled = False
ElseIf MSComm1.Input = "8" Then
Timer1.Enabled = False
Timer2.Enabled = False
Timer3.Enabled = False
Timer4.Enabled = True

End If

End Sub

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


System.EventArgs)

End Sub

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


System.EventArgs)

End Sub

Private Sub OvalShape1_Click_1(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
Static state As Integer
Select Case state

Case 0
OvalShape1.BackColor = Color.Red
OvalShape2.BackColor = Color.White
OvalShape3.BackColor = Color.White
OvalShape4.BackColor = Color.White
Timer1.Interval = 500
state = 1
Case 1
OvalShape1.BackColor = Color.White
OvalShape2.BackColor = Color.Red
OvalShape3.BackColor = Color.Red
OvalShape4.BackColor = Color.Red
Timer1.Interval = 500

state = 0
End Select
End Sub

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


Handles Timer2.Tick
Static state As Integer
Select Case state

Case 0
OvalShape1.BackColor = Color.Red
OvalShape2.BackColor = Color.Red
OvalShape3.BackColor = Color.White
OvalShape4.BackColor = Color.White
Timer2.Interval = 500
state = 1
Case 1
OvalShape1.BackColor = Color.White
OvalShape2.BackColor = Color.White
OvalShape3.BackColor = Color.Red
OvalShape4.BackColor = Color.Red
Timer2.Interval = 500

state = 0
End Select
End Sub

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


Handles Timer3.Tick
Static state As Integer
Select Case state

Case 0
OvalShape1.BackColor = Color.Red
OvalShape2.BackColor = Color.White
OvalShape3.BackColor = Color.Red
OvalShape4.BackColor = Color.White
Timer3.Interval = 500
state = 1
Case 1
OvalShape1.BackColor = Color.White
OvalShape2.BackColor = Color.Red
OvalShape3.BackColor = Color.White
OvalShape4.BackColor = Color.Red
Timer3.Interval = 500

state = 0
End Select
End Sub

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


Handles Timer4.Tick
Static state As Integer
Select Case state

Case 0
OvalShape1.BackColor = Color.White
OvalShape2.BackColor = Color.White
OvalShape3.BackColor = Color.White
OvalShape4.BackColor = Color.White
Timer4.Interval = 500
state = 1
Case 1
OvalShape1.BackColor = Color.Red
OvalShape2.BackColor = Color.Red
OvalShape3.BackColor = Color.Red
OvalShape4.BackColor = Color.Red
Timer4.Interval = 500

state = 0
End Select
End Sub

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


System.EventArgs) Handles OvalShape1.Click

End Sub

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


MSComm1.Output = "5"
End Sub
End Class
 TAMPILAN DI PROTEUS

 TAMPILAN PADA VISUAL BASIC


 JIKA TOMBOL S1 = 1 (DITEKAN)
 JIKA TOMBOL S2 = 1 (DITEKAN)
 JIKA TOMBOL S3= 1 (DITEKAN)
 JIKA TOMBOL S4 = 1 (DITEKAN)

You might also like