Project tutorial
8bit Number Display

8bit Number Display © GPL3+

We convert a decimal number between 0 and 255 to binary and then show the number by using 8 LED.

  • 1,091 views
  • 0 comments
  • 6 respects

Components and supplies

Apps and online services

About this project

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;
       }

Code

CodeC/C++
int p0 = 2;
int p1 = 3;
int p2 = 4;
int p3 = 5;
int p4 = 6;
int p5 = 7;
int p6 = 8;
int p7 = 9; 

void setup() { 
  Serial.begin(9600);
pinMode(p0, OUTPUT); 
pinMode(p1, OUTPUT); 
pinMode(p2, OUTPUT); 
pinMode(p3, OUTPUT); 
pinMode(p4, OUTPUT); 
pinMode(p5, OUTPUT); 
pinMode(p6, OUTPUT); 
pinMode(p7, OUTPUT); 

}

void loop() { 

}
//////////////////
String Splitter(String data, char separator, int index)
{
    int found = 0;
    int strIndex[] = { 0, -1 };
    int maxIndex = data.length() - 1;
    

    for (int i = 0; i <= maxIndex && found <= index; i++) {
        if (data.charAt(i) == separator || i == maxIndex) {
            found++;
            strIndex[0] = strIndex[1] + 1;
            strIndex[1] = (i == maxIndex) ? i+1 : i;
        }
    }
    return found > index ? data.substring(strIndex[0], strIndex[1]) : "";
}
///////////////////////////
void serialEvent (){
  _clear();
  String serialResponse = Serial.readString();
   String Number = Splitter(serialResponse, ';', 0);
   String led0 = Splitter(serialResponse, ';', 1);
   String led1 = Splitter(serialResponse, ';', 2);
   String led2 = Splitter(serialResponse, ';', 3);
   String led3 = Splitter(serialResponse, ';', 4);
   String led4 = Splitter(serialResponse, ';', 5);
   String led5 = Splitter(serialResponse, ';', 6);
   String led6 = Splitter(serialResponse, ';', 7);
   String led7 = Splitter(serialResponse, ';', 8);
   if (led0 == "1") digitalWrite(p0, HIGH); 
      if (led1 == "1") digitalWrite(p1, HIGH); 
         if (led2 == "1") digitalWrite(p2, HIGH); 
            if (led3 == "1") digitalWrite(p3, HIGH); 
               if (led4 == "1") digitalWrite(p4, HIGH); 
                  if (led5 == "1") digitalWrite(p5, HIGH); 
                     if (led6 == "1") digitalWrite(p6, HIGH); 
                        if (led7 == "1") digitalWrite(p7, HIGH); 
}
void _clear()
{
  digitalWrite(p0, LOW); 
  digitalWrite(p1, LOW); 
  digitalWrite(p2, LOW); 
  digitalWrite(p3, LOW); 
  digitalWrite(p4, LOW); 
  digitalWrite(p5, LOW); 
  digitalWrite(p6, LOW);
  digitalWrite(p7, LOW); 

}
  

Custom parts and enclosures

EXE file
8bit_REIJlsR89G.exe

Schematics

do it for 8 led
Examplecircuit bb wse9amy8pf

Comments

Similar projects you might like

GPS Location Display With GPS And TFT Display Shields

Project tutorial by Boian Mitov

  • 15,754 views
  • 6 comments
  • 35 respects

Soil Moisture Sensor With LCD Display

Project tutorial by Patel Darshil

  • 35,981 views
  • 10 comments
  • 55 respects

Digital & Binary Clock In 8 Digits x 7 Segments LED Display

Project tutorial by LAGSILVA

  • 3,301 views
  • 3 comments
  • 11 respects

Lytograph - smart wifi display

Project showcase by ceberocks

  • 3,211 views
  • 0 comments
  • 17 respects

Random Number Generator with 8x8 LED Matrix and Arduino

Project tutorial by LAGSILVA

  • 2,614 views
  • 2 comments
  • 15 respects
Add projectSign up / Login