0% found this document useful (0 votes)
15 views3 pages

DL Led

The document contains code for an Arduino sketch that initializes 8 LED pins as outputs and sets them low by default. It then defines strings to store character values received over serial. In the loop, it receives serial data, parses it into the strings, and uses the strings to control the LED pins - turning them high or low based on the character values. It also includes code for a GUI application that controls the LEDs by writing character strings to the serial port.

Uploaded by

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

DL Led

The document contains code for an Arduino sketch that initializes 8 LED pins as outputs and sets them low by default. It then defines strings to store character values received over serial. In the loop, it receives serial data, parses it into the strings, and uses the strings to control the LED pins - turning them high or low based on the character values. It also includes code for a GUI application that controls the LEDs by writing character strings to the serial port.

Uploaded by

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

void setup(){

  Serial.begin(9600);
  for(int i=2;i<10;i++){
    // 2 la led1 .... 9 la led8
    pinMode(i,OUTPUT);
    digitalWrite(i,LOW);
 }
}
String c1, c2, c3, c4
c5,c6,c7,c8;
void loop() {
  String data;
  while(Serial.available()>0)
 {
    char c = Serial.read();
    data += c;
    delay(5);
 }
  data.trim();
  xuly(data);
  if(c1=="a") {digitalWrite(2,HIGH);}
  if(c1=="b") {digitalWrite(2,LOW);}
  if(c2=="c") {digitalWrite(3,HIGH);}
  if(c2=="d") {digitalWrite(3,LOW);}
  if(c3=="e") {digitalWrite(4,HIGH);}
  if(c3=="f") {digitalWrite(4,LOW);}
}
void xuly(String data)
{
  c1 = data.charAt(0);
  c2 = data.charAt(1);
  c3 = data.charAt(2);
  c4 = data.charAt(3);
  c5 = data.charAt(4);
  c6 = data.charAt(5);
  c7 = data.charAt(6);
  c8 = data.charAt(7);
}
private void GT_Load(object sender, EventArgs e)
{
if (port.IsOpen) port.Close();
b_disconnect.Enabled = false;
try
{
port.PortName = “COM1”;
port.Open();
}
catch (Exception ex)
{
MessageBox.Show("Error! " + ex.Message);
}
}
_public int count;
private void b_send_Click(object sender, EventArgs e)
{
// kiểm tra checkbox 1
if (c_pic1.Checked == true)
{
p1.Image = global::DangNhapDangKy.Properties.Resources.xanh;
s_port1.Write("a");
}
if (c_pic1.Checked == false)
{
p1.Image = global::DangNhapDangKy.Properties.Resources.xam;
s_port1.Write("b");
} *************
}

private void b_flash_Click(object sender, EventArgs e)


{
if (port.IsOpen == true)
{
timer1.Interval = 1000;
timer1.Start();
count = 0;
}
else
{
MessageBox.Show("Error!!! Chưa kết nối Port!", "Lỗi ");
}
}
//
private void timer1_Tick(object sender, EventArgs e)
{
count++;
_if(count == 1)
{
p1.Image = global::DangNhapDangKy.Properties.Resources.xanh;
p2.Image = global::DangNhapDangKy.Properties.Resources. xanh;
p3.Image = global::DangNhapDangKy.Properties.Resources. xanh;
p4.Image = global::DangNhapDangKy.Properties.Resources. xanh;
p5.Image = global::DangNhapDangKy.Properties.Resources. xanh;
p6.Image = global::DangNhapDangKy.Properties.Resources. xanh;
p7.Image = global::DangNhapDangKy.Properties.Resources. xanh;
p8.Image = global::DangNhapDangKy.Properties.Resources. xanh;
_port.Write(“acegilnp”);
}
Else
{
p1.Image = global::DangNhapDangKy.Properties.Resources.xam;
p2.Image = global::DangNhapDangKy.Properties.Resources.xam;
p3.Image = global::DangNhapDangKy.Properties.Resources.xam;
p4.Image = global::DangNhapDangKy.Properties.Resources.xam;
p5.Image = global::DangNhapDangKy.Properties.Resources.xam;
p6.Image = global::DangNhapDangKy.Properties.Resources.xam;
p7.Image = global::DangNhapDangKy.Properties.Resources.xam;
p8.Image = global::DangNhapDangKy.Properties.Resources.xam;
count = 0;
s_port1.Write("bdfhkmoq");
}
}
private void b_clr_Click(object sender, EventArgs e)
{ s_port1.Write("bdfhkmoq");
p1.Image = global::DangNhapDangKy.Properties.Resources.xam;
p2.Image = global::DangNhapDangKy.Properties.Resources.xam;
p3.Image = global::DangNhapDangKy.Properties.Resources.xam;
p4.Image = global::DangNhapDangKy.Properties.Resources.xam;
p5.Image = global::DangNhapDangKy.Properties.Resources.xam;
p6.Image = global::DangNhapDangKy.Properties.Resources.xam;
p7.Image = global::DangNhapDangKy.Properties.Resources.xam;
p8.Image = global::DangNhapDangKy.Properties.Resources.xam;
count = 0;
timer1.Stop();
}

You might also like