Seven Segment Function

edited May 2017 in Share Your Work

It's a auto detect seven segment number display function, hope that someone may need it :)


void setup(){

size(1000,1000);

 background(0);
}

void draw(){
  background(0);

LED_NUMBER(25,200,200,50);  // Number(INT) ,X position, Y position , Size

}



void LED_NUMBER(int score ,float x ,float y,float w){
int n = str(score).length();
float d = w/2.5;
for (int i =1;i=n;i++){   //add "bigger" at i=n
  
int now =int(str(score).substring(-1+i,i));
int off = 0;
int on  = #F00F0F;
int state_a =off,state_b =off,state_c =off,state_d =off,state_e =off,state_f =off,state_g =off;
x=i*w*2.8; //distance

strokeWeight(w/2);

switch(now) {
  case 0: 
     state_a =on;state_b =on;state_c =on;state_d =on;state_e =on;state_f =on;state_g =off;
    break;
  case 1: 
     state_a =off;state_b =on;state_c =on;state_d =off;state_e =off;state_f =off;state_g =off;
    break;
  case 2: 
    state_a =on;state_b =on;state_c =off;state_d =on;state_e =on;state_f =off;state_g =on;
    break;
  case 3: 
   state_a =on;state_b =on;state_c =on;state_d =on;state_e =off;state_f =off;state_g =on;
    break;
  case 4: 
    state_a =off;state_b =on;state_c =on;state_d =off;state_e =off;state_f =on;state_g =on;
    break;
  case 5: 
    state_a =on;state_b =off;state_c =on;state_d =on;state_e =off;state_f =on;state_g =on;
    break;
  case 6: 
    state_a =on;state_b =off;state_c =on;state_d =on;state_e =on;state_f =on;state_g =on;
    break;
  case 7: 
    state_a =on;state_b =on;state_c =on;state_d =off;state_e =off;state_f =off;state_g =off;
    break;
  case 8: 
    state_a =on;state_b =on;state_c =on;state_d =on;state_e =on;state_f =on;state_g =on;
    break;
  case 9: 
    state_a =on;state_b =on;state_c =on;state_d =on;state_e =off;state_f =on;state_g =on;
    break;
  default:
     state_a =off;state_b =off;state_c =off;state_d =off;state_e =off;state_f =off;state_g =off;
    break;
}

stroke(state_a);
line(x  ,y  ,x+w,y  );  //a
stroke(state_b);
line(x+w+d,y+d  ,x+w+d,y+w+d);  //b
stroke(state_c);
line(x+w+d,y+w+d*3  ,x+w+d,y+w*2+d*3);  //c
stroke(state_e);
line(x-d,y+w+d*3  ,x-d,y+w*2+d*3);  //e
stroke(state_f);
line(x-d,y+d  ,x-d,y+w+d);  //f
stroke(state_g);
line(x  ,y+w+d*2  ,x+w,y+w+d*2  );  //g
stroke(state_d);
line(x  ,y+w*3+d*1.5  ,x+w,y+w*3+d*1.5  );  //d
}
}







9487

Comments

  • edited May 2017

    can anyone tell me why there's only 20 lines :(

  • Your code is incomplete. Please fix it.

    Kf

  • it looks great !

    insert empty lines after the code and save the old post or post the code again within the old thread

Sign In or Register to comment.