This is a very simple project. You just connect 8 LED to the Arduino and then input a number and the LEDs show you the number.
private void Send_Click(object sender, EventArgs e)
{
try
{
int IntValue = Convert.ToInt32(Value.Text);
if (IntValue >= 0 && IntValue <=255)
{
string ToSend =Value.Text +";"+ ToBinary(Value.Text);
Console.WriteLine(ToSend);
port.WriteLine(ToSend);
}
else
{
MessageBox.Show("Invalid Input", "Error");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error");
}
}
private string ToBinary(string data)
{
string result = string.Empty;
int rem = 0;
try
{
int num = int.Parse(data);
for (int i = 0; i < 8; i++)
{
rem = num % 2;
num = num / 2;
result = rem.ToString() + ";" + result;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error");
}
Seprate(result);
return result;
}
private void Seprate(string result)
{
String[] bits = result.Split(';');
if (bits[7] == "0") { p0.Checked = false; } else if (bits[7] == "1") p0.Checked = true;
if (bits[6] == "0") { p1.Checked = false; } else if (bits[6] == "1") p1.Checked = true;
if (bits[5] == "0") { p2.Checked = false; } else if (bits[5] == "1") p2.Checked = true;
if (bits[4] == "0") { p3.Checked = false; } else if (bits[4] == "1") p3.Checked = true;
if (bits[3] == "0") { p4.Checked = false; } else if (bits[3] == "1") p4.Checked = true;
if (bits[2] == "0") { p5.Checked = false; } else if (bits[2] == "1") p5.Checked = true;
if (bits[1] == "0") { p6.Checked = false; } else if (bits[1] == "1") p6.Checked = true;
if (bits[0] == "0") { p7.Checked = false; } else if (bits[0] == "1") p7.Checked = true;
}
10 projects • 69 followers
Hey guys! I'm Alireza. I'm a student (Bachelor of Technology)-Computer EngrgTech. I'm C# / C++ / Unity programmer and familiar to Front-End.
Comments