Eh, kali ini saya pakai Visual Studio loh bikinnya bukan pakai SharpDevelop lagi :D
pengen tampil beda aja sih :v
langsung ke codingannya aja ya guys, ini dia :
ini untuk codingan Tombol On/Off nya ->>>>>>>>
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Tombol_On_Off
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
if (button1.Text == "CONNECT")
{
serialPort1.PortName = comboBox2.Text;
serialPort1.BaudRate = Convert.ToInt16(comboBox1.Text);
serialPort1.Open();
button1.Text = "DISCONNECT";
}
else
{
serialPort1.Close();
button1.Text = "CONNECT";
}
}
int a=0, b=0, c=0;
private void pictureBox1_Click(object sender, EventArgs e)
{
if (a == 1)
{
serialPort1.Write("1");
pictureBox1.Image = Tombol_On_Off.Resource1.tombol_on;
a = 0;
label1.BackColor = Color.Green;
label2.BackColor = Color.Red;
}
else
{
serialPort1.Write("0");
pictureBox1.Image = Tombol_On_Off.Resource1.tombol_off;
a = 1;
label2.BackColor = Color.Green;
label1.BackColor = Color.Red;
}
}
private void pictureBox2_Click(object sender, EventArgs e)
{
if (b == 1)
{
serialPort1.Write("3");
pictureBox2.Image = Tombol_On_Off.Resource1.tombol_on;
b = 0;
label3.BackColor = Color.Green;
label4.BackColor = Color.Red;
}
else
{
serialPort1.Write("2");
pictureBox2.Image = Tombol_On_Off.Resource1.tombol_off;
b = 1;
label4.BackColor = Color.Green;
label3.BackColor = Color.Red;
}
}
private void pictureBox3_Click(object sender, EventArgs e)
{
if (c == 1)
{
serialPort1.Write("5");
pictureBox3.Image = Tombol_On_Off.Resource1.tombol_on;
c = 0;
label5.BackColor = Color.Green;
label6.BackColor = Color.Red;
}
else
{
serialPort1.Write("4");
pictureBox3.Image = Tombol_On_Off.Resource1.tombol_off;
c = 1;
label6.BackColor = Color.Green;
label5.BackColor = Color.Red;
}
}
}
}
ini untuk codingan Lampu LED nya ->>>>>>>>
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace _3_Lampu_LED
{
public partial class Form1 : Form
{
string a;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
if (button1.Text == "CONNECT")
{
serialPort1.PortName = comboBox1.Text;
serialPort1.BaudRate = Convert.ToInt16(comboBox2.Text);
serialPort1.Open();
button1.Text = "DISCONNECT";
}
else
{
serialPort1.Close();
button1.Text = "CONNECT";
}
}
catch (Exception y)
{
MessageBox.Show("Cek Port");
}
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
if (textBox1.Text == "0")
{
pictureBox1.Image = _3_Lampu_LED.Resource1.lampu_mati;
textBox1.ResetText();
}
else if (textBox1.Text == "1")
{
pictureBox1.Image = _3_Lampu_LED.Resource1.latar_jam_digital;
textBox1.ResetText();
}
else if (textBox1.Text == "2")
{
pictureBox2.Image = _3_Lampu_LED.Resource1.lampu_mati;
textBox1.ResetText();
}
else if (textBox1.Text == "3")
{
pictureBox2.Image = _3_Lampu_LED.Resource1.latar_jam_digital;
textBox1.ResetText();
}
else if (textBox1.Text == "4")
{
pictureBox3.Image = _3_Lampu_LED.Resource1.lampu_mati;
textBox1.ResetText();
}
else if (textBox1.Text == "5")
{
pictureBox3.Image = _3_Lampu_LED.Resource1.latar_jam_digital;
textBox1.ResetText();
}
}
private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
a = serialPort1.ReadExisting();
this.Invoke(new EventHandler(dp));
}
public void dp(object sender, EventArgs e)
{
textBox1.AppendText(a);
}
}
}Ini gambarannya ya guys ketika di Running programnya ;)
Sekian postingan blog saya kali ini, semoga bermanfaat. dan dapat dikembangkan lagi ya guys?
jika ingin bertanya silahkan tinggalkan pesan ;).
No comments:
Post a Comment