Alireza Karkon
Published © GPL3+

8bit Number Display

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

EasyFull instructions provided1 hour784
8bit Number Display

Things used in this project

Story

Read more

Custom parts and enclosures

EXE file

Schematics

Led

do it for 8 led
Examplecircuit bb wse9amy8pf

Code

Code

C/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); 

}
  

Credits

Alireza Karkon

Alireza Karkon

7 projects • 20 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