// allviews grid jumper ic circuit45 circuit30 include dotray=1; dotdistx=5; dotdisty=5; rowx=30; module gridsimple(cols,rows){ color("yellow") for (i=[1:cols]){ translate([(i-1)*rowx,0,0]){ for (j=[1:rows]){ translate([0,(j-1)*dotdisty,0]){ for (k=[1:5]){ translate([(k-1)*dotdistx,0,0]) circle(r=dotray,$fn=40); } } } } } color("black"){ for (x=[1:5:rows]){ for (i=[x:x+2]){ translate([-7,(i-1)*dotdisty,0]) circle(r=dotray,$fn=40); translate([-17,(i-1)*dotdisty-1,0]) text(str(i),size=3); } } } color("red"){ for (x=[1:5:rows]){ for (i=[x:x+2]){ translate([2*rowx-3,(i+1)*dotdisty,0]) circle(r=dotray,$fn=40); } } } } module griddouble(cols,rows){ color("yellow") for (i=[1:cols]){ translate([(i-1)*rowx,0,0]){ for (j=[1:rows]){ translate([0,(j-1)*dotdisty,0]){ for (k=[1:5]){ translate([(k-1)*dotdistx,0,0]) circle(r=dotray,$fn=40); } } } } } color("black"){ for (i=[1:rows]){ translate([-7,(i-1)*dotdisty,0]) circle(r=dotray,$fn=40); translate([-17,(i-1)*dotdisty-1,0]) text(str(i),size=3); } for (i=[1:rows]){ translate([2*rowx+1,(i-1)*dotdisty,0]) circle(r=dotray,$fn=40); } } color("red"){ for (i=[1:rows]){ translate([-11,(i-1)*dotdisty,0]) circle(r=dotray,$fn=40); } for (i=[1:rows]){ translate([2*rowx-3,(i-1)*dotdisty,0]) circle(r=dotray,$fn=40); } } } module jumperxy (x1,y1,x2,y2,type,col,extra){ *translate([x1,y1,0]) circle(r=dotray,$fn=40); *translate([x2,y2,0]) circle(r=dotray,$fn=40); diffy=y2-y1; diffx=x2-x1; angle=atan2(diffy,diffx); len=sqrt(diffy*diffy+diffx*diffx); translate([x1,y1,0]) rotate([0,0,angle]){ color(col) translate([0,-0.5,0]) polygon(points=[[0,0],[len,0],[len,1],[0,1],[0,0]]); if (type == "resistor"){ lenres=15; translate([len/2-lenres/2,0,0]){ color("lightblue") rotate([0,90,0]) cylinder(r=2,h=lenres,$fn=40); for (i=[1:4]){ color(extra[i-1]) translate([i*2.5,0,0]) rotate([0,90,0]) cylinder(r=2.1,h=1,$fn=40); } } }else if (type == "diode"){ color("black") translate([len/2-1,0.5,0.5]){ l=2.5; polygon([[0,0],[0,l],[l,0] ,[l,l],[l+1,l],[l+1,-l],[l,-l],[l,0],[0,-l],[0,0]]); } }else if (type == "led"){ translate([len/2,0.5,0.5]){ color("black") translate([0,0,0.5]) circle(r=3,$fn=40); color("white") translate([0,0,1]) circle(r=2,$fn=40); l=2.5; color("black") translate([-1,0,2]) polygon([[0,0],[0,l],[l,0] ,[l,l],[l+1,l],[l+1,-l],[l,-l],[l,0],[0,-l],[0,0]]); } } } } module jumperx (x1,y1,p2,type,col,extra){ y2=(p2.y-1)*dotdisty; if (p2.x==-1){ // Ground bus x2 = -7; jumperxy(x1,y1,x2,y2,type,col,extra); }else if (p2.x==2){ // Vcc bus x2 = 2*rowx-3; jumperxy(x1,y1,x2,y2,type,col,extra); }else{ x2=p2.x*rowx+p2[3]*dotdistx; jumperxy(x1,y1,x2,y2,type,col,extra); } } module jumper_vertical(x,y,z,col){ color(col) translate([x,y,0]) cylinder(r=0.55,h=2.5+z*2,$fn=20); } module jumper(p1,p2,type,col,extra){ y1=(p1.y-1)*dotdisty; if (p1.x == p2.x && p1.y == p2.y && p1[3] == p2[3]){ // jumper vertical if (p1.x==-1){ jumper_vertical(-7,y1,p2.z,col); }else if (p1.x == 2){ x1 = 2*rowx-3; jumper_vertical(x1,y1,p2.z,col); }else{ x1=p1.x*rowx+p1[3]*dotdistx; jumper_vertical(x1,y1,p2.z,col); } }else{ translate([0,0,2+p1.z*2]){ if (p1.x==-1){ // Ground bus x1 = -7; jumperx(x1,y1,p2,type,col,extra); }else if (p1.x==2){ // Vcc bus x1 = 2*rowx-3; jumperx(x1,y1,p2,type,col,extra); }else{ x1=p1.x*rowx+p1[3]*dotdistx; jumperx(x1,y1,p2,type,col,extra); } } } } module ic(y,nb,col,name){ nb2=nb/2; y_1 = y-1; color(col){ translate([4*dotdistx-1,y_1*dotdisty-2,4]) square([12,(nb2-1)*dotdisty+4]); } color("white"){ translate([4*dotdistx+1,y_1*dotdisty,5]){ translate([0,(nb2-1)*dotdisty,0]) circle(r=1,$fn=40); translate([0,0,0]) text(name,size=3); } } } module to220(x,y,hole,reverse,col,name){ offx = reverse ? -5 : 0; offsink = reverse ? -5 : 3; color(col){ translate([x*rowx+hole*dotdistx-1+offx,(y-1)*dotdisty-2,4]){ square([6,3*dotdisty-2]); } } color("gray"){ translate([x*rowx+hole*dotdistx+offsink,(y-1)*dotdisty-2,4.1]){ square([2,3*dotdisty-2]); } } } module connector(x,y,hole,nbpin,col,type,name){ len=nbpin*dotdisty; translate([x*rowx+hole*dotdistx-2.5,(y-1)*dotdisty-2,0]){ color(col){ if (type == 0){ cube([5,len,2]); }else{ difference(){ cube([5,len,5]); for (i=[0:nbpin-1]){ translate([2.5,len/nbpin*i+2.5,2]) cylinder(r=1,h=6,$fn=40); } } } } color("white"){ for (i=[0:nbpin-1]){ translate([2.5,len/nbpin*i+2.5,2]) cylinder(r=1,h=type==0 ? 4 : 2,$fn=40); } } } } module main_view(view){ if (view=="grid"){ grid(2,45); }else if (view=="jumper"){ grid(2,45); jumper([0,0,0],[1,0,0],"red"); jumper([0,5,4],[1,5,0],"blue"); jumper([0,3,1],[1,4,2],"blue"); ic (10,4,"black"); }else if (view=="ic"){ ic(10,4,"black"); }else if (view=="circuit45"){ gridsimple(2,45); include }else if (view=="circuit30"){ griddouble(2,30); include } }