Sunday, April 8, 2012

7 bit Display


This code will show you the current time - in 24 hour FORMAT


MAIN CLASS


digh hours = new digh(); //To intialise Hours Class
digm minutes = new digm(); //To intialise Minutes Class
digs seconds = new digs(); //To intialise Seconds Class
int dots = 0;


void setup() {
  background(0);
  size(1000, 400);
  dots = min(height, width); //To adjust the dots according to the screen size
}


void draw() {
  background(0);


  hours.digit(hour()); //To call hours class with the value of current Hour
  minutes.digit(minute()); //To call hours class with the value of current Minute
  seconds.digit(second()); //To call hours class with the value of current Second


  ellipse(7*width/20, 9*height/20, dots/25, dots/25);
  ellipse(7*width/20, 11*height/20, dots/25, dots/25);


  ellipse(12*width/20, 9*height/20, dots/25, dots/25);
  ellipse(12*width/20, 11*height/20, dots/25, dots/25);
}

HOUR CLASS
class digh {
  int [] digf = new int[7];//The bits required for first Digit
  int [] digs = new int[7];//The bits required for first Digit

  int fhour;//To keep the value of first digit
  int shour;//To keep the value of first digit

  void digit(int num) {
    shour = num%10; //To take out the second digit from the value given
    fhour = num/10; //To take out the first digit from the value given
    draw();//To call the draw method
    ///////////////////////*FIRST HOUR*/////////////////////////////////
    if (fhour ==0) {  //Used for displaying '0'
      digf[0]=1; //the left up bit
      digf[1]=1; //the left down bit
      digf[2]=1; //the right up bit
      digf[3]=1; //the right down bit
      digf[4]=1; //center up bit
      digf[5]=0; //center mid bit
      digf[6]=1; //center down bit
    }

    if (fhour ==1) {  //Used for displaying '1'
      digf[0]=0;
      digf[1]=0;
      digf[2]=1;
      digf[3]=1;
      digf[4]=0;
      digf[5]=0;
      digf[6]=0;
    }

    if (fhour ==2) {  //Used for displaying '2'
      digf[0]=0;
      digf[1]=1;
      digf[2]=1;
      digf[3]=0;
      digf[4]=1;
      digf[5]=1;
      digf[6]=1;
    }
    if (fhour ==3) {  //Used for displaying '3'
      digf[0]=0;
      digf[1]=0;
      digf[2]=1;
      digf[3]=1;
      digf[4]=1;
      digf[5]=1;
      digf[6]=1;
    }

    if (fhour ==4) {  //Used for displaying '4'
      digf[0]=1;
      digf[1]=0;
      digf[2]=1;
      digf[3]=1;
      digf[4]=0;
      digf[5]=1;
      digf[6]=0;
    }

    if (fhour ==5) {  //Used for displaying '5'
      digf[0]=1;
      digf[1]=0;
      digf[2]=0;
      digf[3]=1;
      digf[4]=1;
      digf[5]=1;
      digf[6]=1;
    }
    if (fhour ==6) {  //Used for displaying '6'
      digf[0]=1;
      digf[1]=1;
      digf[2]=0;
      digf[3]=1;
      digf[4]=1;
      digf[5]=1;
      digf[6]=1;
    }
    if (fhour ==7) {  //Used for displaying '7'
      digf[0]=0;
      digf[1]=0;
      digf[2]=1;
      digf[3]=1;
      digf[4]=1;
      digf[5]=0;
      digf[6]=0;
    }

    if (fhour ==8) {  //Used for displaying '8'
      digf[0]=1;
      digf[1]=1;
      digf[2]=1;
      digf[3]=1;
      digf[4]=1;
      digf[5]=1;
      digf[6]=1;
    }
    if (fhour ==9) {  //Used for displaying '9'
      digf[0]=1;
      digf[1]=0;
      digf[2]=1;
      digf[3]=1;
      digf[4]=1;
      digf[5]=1;
      digf[6]=1;
    }
    /////////////////////////////*FIRST HOUR END*//////////////////////////////

    ////////////////////////////*SECOND HOUR*///////////////////////////////////
    if (shour==0) {  //Used for displaying '0'
      digs[0]=1;
      digs[1]=1;
      digs[2]=1;
      digs[3]=1;
      digs[4]=1;
      digs[5]=0;
      digs[6]=1;
    }

    if (shour==1) {  //Used for displaying '1'
      digs[0]=0;
      digs[1]=0;
      digs[2]=1;
      digs[3]=1;
      digs[4]=0;
      digs[5]=0;
      digs[6]=0;
    }

    if (shour==2) {  //Used for displaying '2'
      digs[0]=0;
      digs[1]=1;
      digs[2]=1;
      digs[3]=0;
      digs[4]=1;
      digs[5]=1;
      digs[6]=1;
    }
    if (shour==3) {  //Used for displaying '3'
      digs[0]=0;
      digs[1]=0;
      digs[2]=1;
      digs[3]=1;
      digs[4]=1;
      digs[5]=1;
      digs[6]=1;
    }

    if (shour==4) {  //Used for displaying '4'
      digs[0]=1;
      digs[1]=0;
      digs[2]=1;
      digs[3]=1;
      digs[4]=0;
      digs[5]=1;
      digs[6]=0;
    }

    if (shour==5) {  //Used for displaying '5'
      digs[0]=1;
      digs[1]=0;
      digs[2]=0;
      digs[3]=1;
      digs[4]=1;
      digs[5]=1;
      digs[6]=1;
    }
    if (shour==6) {  //Used for displaying '6'
      digs[0]=1;
      digs[1]=1;
      digs[2]=0;
      digs[3]=1;
      digs[4]=1;
      digs[5]=1;
      digs[6]=1;
    }
    if (shour==7) {  //Used for displaying '7'
      digs[0]=0;
      digs[1]=0;
      digs[2]=1;
      digs[3]=1;
      digs[4]=1;
      digs[5]=0;
      digs[6]=0;
    }

    if (shour==8) {  //Used for displaying '8'
      digs[0]=1;
      digs[1]=1;
      digs[2]=1;
      digs[3]=1;
      digs[4]=1;
      digs[5]=1;
      digs[6]=1;
    }
    if (shour==9) {  //Used for displaying '9'
      digs[0]=1;
      digs[1]=0;
      digs[2]=1;
      digs[3]=1;
      digs[4]=1;
      digs[5]=1;
      digs[6]=1;
    }
    //////////////////////////*SECOND HOUR END*//////////////////////////////////////
  } 

  void draw() { //Used to draw Numbers on screen

    noStroke();//to clear out the bounderies of the numbers
    ellipseMode(CORNER);//Used to set the drawing method of ellipse
    fill(0);//The default fill colour of the numbers to be BLACK
    
    
    ////////////////////*SECOND HOUR START*///////////////////////////////////////
    
    if (digs[0]==1) { //The Left Up Bit
      fill(2, 155, 0);
      ellipse(5*width/20, 6*height/20, width/60, height/5);
    }

    if (digs[1]==1) { //Left Down Bit
      fill(2, 155, 0);
      ellipse(5*width/20, 11*height/20, width/60, height/5);
    }

    if (digs[2] ==1) { //Right Up Bit
      fill(2, 155, 0);
      ellipse(6*width/20, 6*height/20, width/60, height/5);
    }

    if (digs[3]==1) { //Right down bit
      fill(2, 155, 0);
      ellipse(6*width/20, 11*height/20, width/60, height/5);
    }

    if (digs[4]==1) { //Center up bit
      fill(2, 155, 0);  
      ellipse(13*width/50, 8*height/30, height/8, width/70);
    }

    if (digs[5]==1) { //center middle bit
      fill(2, 155, 0);
      ellipse(13*width/50, 15*height/30, height/8, width/70);
    }

    if (digs[6]==1) { //center down bit
      fill(2, 155, 0);
      ellipse(13*width/50, 22*height/30, height/8, width/70);
    }

    ////////////////////*SECOND HOUR END*///////////////////////////////////////
    ////////////////////*FIRST HOUR START*///////////////////////////////////////
    if (digf[0]==1) {
      fill(2, 155, 0);
      ellipse(3*width/20, 6*height/20, width/60, height/5);
    }

    if (digf[1]==1) {
      fill(2, 155, 0);
      ellipse(3*width/20, 11*height/20, width/60, height/5);
    }

    if (digf[2] ==1) {
      fill(2, 155, 0);
      ellipse(4*width/20, 6*height/20, width/60, height/5);
    }




    if (digf[3]==1) {
      fill(2, 155, 0);
      ellipse(4*width/20, 11*height/20, width/60, height/5);
    }



    if (digf[4]==1) {
      fill(2, 155, 0);  
      ellipse(8*width/50, 8*height/30, height/8, width/70);
    }


    if (digf[5]==1) {
      fill(2, 155, 0);
      ellipse(8*width/50, 15*height/30, height/8, width/70);
    }




    if (digf[6]==1) {
      fill(2, 155, 0);
      ellipse(8*width/50, 22*height/30, height/8, width/70);
    } 
    ////////////////////*FIRST HOUR END*///////////////////////////////////////
  }

MINUTES CLASS
class digm {
  int [] digf = new int[7];
  int [] digs = new int[7];

  int fminute;
  int sminute;


  void digit(int num) {
    sminute = num%10;  
    fminute = num/10;
    draw();
    ///////////////////////*FIRST minute*/////////////////////////////////
    if (fminute ==0) {  
      digf[0]=1;
      digf[1]=1;
      digf[2]=1;
      digf[3]=1;
      digf[4]=1;
      digf[5]=0;
      digf[6]=1;
    }

    if (fminute ==1) {  
      digf[0]=0;
      digf[1]=0;
      digf[2]=1;
      digf[3]=1;
      digf[4]=0;
      digf[5]=0;
      digf[6]=0;
    }

    if (fminute ==2) {  
      digf[0]=0;
      digf[1]=1;
      digf[2]=1;
      digf[3]=0;
      digf[4]=1;
      digf[5]=1;
      digf[6]=1;
    }
    if (fminute ==3) {  
      digf[0]=0;
      digf[1]=0;
      digf[2]=1;
      digf[3]=1;
      digf[4]=1;
      digf[5]=1;
      digf[6]=1;
    }

    if (fminute ==4) {  
      digf[0]=1;
      digf[1]=0;
      digf[2]=1;
      digf[3]=1;
      digf[4]=0;
      digf[5]=1;
      digf[6]=0;
    }

    if (fminute ==5) {  
      digf[0]=1;
      digf[1]=0;
      digf[2]=0;
      digf[3]=1;
      digf[4]=1;
      digf[5]=1;
      digf[6]=1;
    }
    if (fminute ==6) {  
      digf[0]=1;
      digf[1]=1;
      digf[2]=0;
      digf[3]=1;
      digf[4]=1;
      digf[5]=1;
      digf[6]=1;
    }
    if (fminute ==7) {  
      digf[0]=0;
      digf[1]=0;
      digf[2]=1;
      digf[3]=1;
      digf[4]=1;
      digf[5]=0;
      digf[6]=0;
    }

    if (fminute ==8) {  
      digf[0]=1;
      digf[1]=1;
      digf[2]=1;
      digf[3]=1;
      digf[4]=1;
      digf[5]=1;
      digf[6]=1;
    }
    if (fminute ==9) {  
      digf[0]=1;
      digf[1]=0;
      digf[2]=1;
      digf[3]=1;
      digf[4]=1;
      digf[5]=1;
      digf[6]=1;
    }
    /////////////////////////////*FIRST minute END*//////////////////////////////

    ////////////////////////////*SECOND minute*///////////////////////////////////
    if (sminute==0) {  
      digs[0]=1;
      digs[1]=1;
      digs[2]=1;
      digs[3]=1;
      digs[4]=1;
      digs[5]=0;
      digs[6]=1;
    }

    if (sminute==1) {  
      digs[0]=0;
      digs[1]=0;
      digs[2]=1;
      digs[3]=1;
      digs[4]=0;
      digs[5]=0;
      digs[6]=0;
    }

    if (sminute==2) {  
      digs[0]=0;
      digs[1]=1;
      digs[2]=1;
      digs[3]=0;
      digs[4]=1;
      digs[5]=1;
      digs[6]=1;
    }
    if (sminute==3) {  
      digs[0]=0;
      digs[1]=0;
      digs[2]=1;
      digs[3]=1;
      digs[4]=1;
      digs[5]=1;
      digs[6]=1;
    }

    if (sminute==4) {  
      digs[0]=1;
      digs[1]=0;
      digs[2]=1;
      digs[3]=1;
      digs[4]=0;
      digs[5]=1;
      digs[6]=0;
    }

    if (sminute==5) {  
      digs[0]=1;
      digs[1]=0;
      digs[2]=0;
      digs[3]=1;
      digs[4]=1;
      digs[5]=1;
      digs[6]=1;
    }
    if (sminute==6) {  
      digs[0]=1;
      digs[1]=1;
      digs[2]=0;
      digs[3]=1;
      digs[4]=1;
      digs[5]=1;
      digs[6]=1;
    }
    if (sminute==7) {  
      digs[0]=0;
      digs[1]=0;
      digs[2]=1;
      digs[3]=1;
      digs[4]=1;
      digs[5]=0;
      digs[6]=0;
    }

    if (sminute==8) {  
      digs[0]=1;
      digs[1]=1;
      digs[2]=1;
      digs[3]=1;
      digs[4]=1;
      digs[5]=1;
      digs[6]=1;
    }
    if (sminute==9) {  
      digs[0]=1;
      digs[1]=0;
      digs[2]=1;
      digs[3]=1;
      digs[4]=1;
      digs[5]=1;
      digs[6]=1;
    }
    //////////////////////////*SECOND minute END*//////////////////////////////////////
  } 

  void draw() {

    noStroke();
    ellipseMode(CORNER);
    fill(255);
    ////////////////////*SECOND minute START*///////////////////////////////////////
    if (digs[0]==1) {
      fill(2, 155, 0);
      ellipse(10*width/20, 6*height/20, width/60, height/5);
    }

    if (digs[1]==1) {
      fill(2, 155, 0);
      ellipse(10*width/20, 11*height/20, width/60, height/5);
    }

    if (digs[2] ==1) {
      fill(2, 155, 0);
      ellipse(11*width/20, 6*height/20, width/60, height/5);
    }

    if (digs[3]==1) {
      fill(2, 155, 0);
      ellipse(11*width/20, 11*height/20, width/60, height/5);
    }

    if (digs[4]==1) {
      fill(2, 155, 0);  
      ellipse(25.5*width/50, 8*height/30, height/8, width/70);
    }

    if (digs[5]==1) {
      fill(2, 155, 0);
      ellipse(25.5*width/50, 15*height/30, height/8, width/70);
    }

    if (digs[6]==1) {
      fill(2, 155, 0);
      ellipse(25.5*width/50, 22*height/30, height/8, width/70);
    }

    ////////////////////*SECOND minute END*///////////////////////////////////////
    ////////////////////*FIRST minute START*///////////////////////////////////////
    if (digf[0]==1) {
      fill(2, 155, 0);
      ellipse(8*width/20, 6*height/20, width/60, height/5);
    }

    if (digf[1]==1) {
      fill(2, 155, 0);
      ellipse(8*width/20, 11*height/20, width/60, height/5);
    }

    if (digf[2] ==1) {
      fill(2, 155, 0);
      ellipse(9*width/20, 6*height/20, width/60, height/5);
    }

    if (digf[3]==1) {
      fill(2, 155, 0);
      ellipse(9*width/20, 11*height/20, width/60, height/5);
    }



    if (digf[4]==1) {
      fill(2, 155, 0);  
      ellipse(20.5*width/50, 8*height/30, height/8, width/70);
    }

    if (digf[5]==1) {
      fill(2, 155, 0);
      ellipse(20.5*width/50, 15*height/30, height/8, width/70);
    }

    if (digf[6]==1) {
      fill(2, 155, 0);
      ellipse(20.5*width/50, 22*height/30, height/8, width/70);
    } 
    ////////////////////*FIRST minute END*///////////////////////////////////////
  }

SECONDS CLASS
class digs {
  int [] digf = new int[7];
  int [] digs = new int[7];

  int fsecond;
  int ssecond;


  void digit(int num) {
    ssecond = num%10;  
    fsecond = num/10;
    draw();
    ///////////////////////*FIRST second*/////////////////////////////////
    if (fsecond ==0) {  
      digf[0]=1;
      digf[1]=1;
      digf[2]=1;
      digf[3]=1;
      digf[4]=1;
      digf[5]=0;
      digf[6]=1;
    }

    if (fsecond ==1) {  
      digf[0]=0;
      digf[1]=0;
      digf[2]=1;
      digf[3]=1;
      digf[4]=0;
      digf[5]=0;
      digf[6]=0;
    }

    if (fsecond ==2) {  
      digf[0]=0;
      digf[1]=1;
      digf[2]=1;
      digf[3]=0;
      digf[4]=1;
      digf[5]=1;
      digf[6]=1;
    }
    if (fsecond ==3) {  
      digf[0]=0;
      digf[1]=0;
      digf[2]=1;
      digf[3]=1;
      digf[4]=1;
      digf[5]=1;
      digf[6]=1;
    }

    if (fsecond ==4) {  
      digf[0]=1;
      digf[1]=0;
      digf[2]=1;
      digf[3]=1;
      digf[4]=0;
      digf[5]=1;
      digf[6]=0;
    }

    if (fsecond ==5) {  
      digf[0]=1;
      digf[1]=0;
      digf[2]=0;
      digf[3]=1;
      digf[4]=1;
      digf[5]=1;
      digf[6]=1;
    }
    if (fsecond ==6) {  
      digf[0]=1;
      digf[1]=1;
      digf[2]=0;
      digf[3]=1;
      digf[4]=1;
      digf[5]=1;
      digf[6]=1;
    }
    if (fsecond ==7) {  
      digf[0]=0;
      digf[1]=0;
      digf[2]=1;
      digf[3]=1;
      digf[4]=1;
      digf[5]=0;
      digf[6]=0;
    }

    if (fsecond ==8) {  
      digf[0]=1;
      digf[1]=1;
      digf[2]=1;
      digf[3]=1;
      digf[4]=1;
      digf[5]=1;
      digf[6]=1;
    }
    if (fsecond ==9) {  
      digf[0]=1;
      digf[1]=0;
      digf[2]=1;
      digf[3]=1;
      digf[4]=1;
      digf[5]=1;
      digf[6]=1;
    }
    /////////////////////////////*FIRST second END*//////////////////////////////

    ////////////////////////////*SECOND second*///////////////////////////////////
    if (ssecond==0) {  
      digs[0]=1;
      digs[1]=1;
      digs[2]=1;
      digs[3]=1;
      digs[4]=1;
      digs[5]=0;
      digs[6]=1;
    }

    if (ssecond==1) {  
      digs[0]=0;
      digs[1]=0;
      digs[2]=1;
      digs[3]=1;
      digs[4]=0;
      digs[5]=0;
      digs[6]=0;
    }

    if (ssecond==2) {  
      digs[0]=0;
      digs[1]=1;
      digs[2]=1;
      digs[3]=0;
      digs[4]=1;
      digs[5]=1;
      digs[6]=1;
    }
    if (ssecond==3) {  
      digs[0]=0;
      digs[1]=0;
      digs[2]=1;
      digs[3]=1;
      digs[4]=1;
      digs[5]=1;
      digs[6]=1;
    }

    if (ssecond==4) {  
      digs[0]=1;
      digs[1]=0;
      digs[2]=1;
      digs[3]=1;
      digs[4]=0;
      digs[5]=1;
      digs[6]=0;
    }

    if (ssecond==5) {  
      digs[0]=1;
      digs[1]=0;
      digs[2]=0;
      digs[3]=1;
      digs[4]=1;
      digs[5]=1;
      digs[6]=1;
    }
    if (ssecond==6) {  
      digs[0]=1;
      digs[1]=1;
      digs[2]=0;
      digs[3]=1;
      digs[4]=1;
      digs[5]=1;
      digs[6]=1;
    }
    if (ssecond==7) {  
      digs[0]=0;
      digs[1]=0;
      digs[2]=1;
      digs[3]=1;
      digs[4]=1;
      digs[5]=0;
      digs[6]=0;
    }

    if (ssecond==8) {  
      digs[0]=1;
      digs[1]=1;
      digs[2]=1;
      digs[3]=1;
      digs[4]=1;
      digs[5]=1;
      digs[6]=1;
    }
    if (ssecond==9) {  
      digs[0]=1;
      digs[1]=0;
      digs[2]=1;
      digs[3]=1;
      digs[4]=1;
      digs[5]=1;
      digs[6]=1;
    }
    //////////////////////////*SECOND second END*//////////////////////////////////////
  } 

 void draw() {

    noStroke();
    ellipseMode(CORNER);
    fill(255);
    ////////////////////*SECOND second START*///////////////////////////////////////
    if (digs[0]==1) {
      fill(2, 155, 0);
      ellipse(15*width/20, 6*height/20, width/60, height/5);
    }

    if (digs[1]==1) {
      fill(2, 155, 0);
      ellipse(15*width/20, 11*height/20, width/60, height/5);
    }

    if (digs[2] ==1) {
      fill(2, 155, 0);
      ellipse(16*width/20, 6*height/20, width/60, height/5);
    }

    if (digs[3]==1) {
      fill(2, 155, 0);
      ellipse(16*width/20, 11*height/20, width/60, height/5);
    }

    if (digs[4]==1) {
      fill(2, 155, 0);  
      ellipse(38*width/50, 8*height/30, height/8, width/70);
    }

    if (digs[5]==1) {
      fill(2, 155, 0);
      ellipse(38*width/50, 15*height/30, height/8, width/70);
    }

    if (digs[6]==1) {
      fill(2, 155, 0);
      ellipse(38*width/50, 22*height/30, height/8, width/70);
    }

    ////////////////////*SECOND second END*///////////////////////////////////////
    ////////////////////*FIRST second START*///////////////////////////////////////
    if (digf[0]==1) {
      fill(2, 155, 0);
      ellipse(13*width/20, 6*height/20, width/60, height/5);
    }


    if (digf[1]==1) {
      fill(2, 155, 0);
      ellipse(13*width/20, 11*height/20, width/60, height/5);
    }

    if (digf[2] ==1) {
      fill(2, 155, 0);
      ellipse(14*width/20, 6*height/20, width/60, height/5);
    }

    if (digf[3]==1) {
      fill(2, 155, 0);
      ellipse(14*width/20, 11*height/20, width/60, height/5);
    }

    if (digf[4]==1) {
      fill(2, 155, 0);  
      ellipse(33*width/50, 8*height/30, height/8, width/70);
    }

    if (digf[5]==1) {
      fill(2, 155, 0);
      ellipse(33*width/50, 15*height/30, height/8, width/70);
    }

    if (digf[6]==1) {
      fill(2, 155, 0);
      ellipse(33*width/50, 22*height/30, height/8, width/70);
    } 
    ////////////////////*FIRST second END*///////////////////////////////////////
  }


*For the explanation of minutes and second, refer to the hour class. The explanation is the same