use <gears/gears.scad>

$fn = 50;
gear_modul = 1;
gear_tooth_number_small = 10;
gear_tooth_number_large = 150;
gear_large_full_diameter = 190;

module brett () {
    difference () {
        cylinder(d=197, h=12);
        cylinder(d=15.5, h=12);
    }
}

module stepper_zahnrad () {
    difference () {
        union () {
            translate([0,0,10]) spur_gear(modul=gear_modul, tooth_number=gear_tooth_number_small, width=3, bore=0);
            cylinder(h=10+3, d=6.5+2);
         }
        stepper_welle();
    }
}

module stepper_welle () {
    difference() {   
            cylinder(d=6.5,h=71.5);
            translate([6,0,0]) cube([6.5,6.5,71.5 *2], center = true);
        }
}

module stepper () { 
    union () {
        translate([-56.5 / 2, -56.5 / 2, 0]) union () {
            difference () {
                //Grundkörper
                cube([56.5,56.5,50.5]);
            
                //Einrundungen
                cylinder(h=45,r=9.5);
                translate([56.5, 0,0]) cylinder(45,9.5,9.5);
                translate([0, 56.5,0]) cylinder(45,9.5,9.5);
                translate([56.5, 56.5,0]) cylinder(45,9.5,9.5);
                
                //Schrauben
                translate([4,4,45]) cylinder(h=6,d=5.5);
                translate([56.5-4,4,45]) cylinder(h=6,d=5.5);
                translate([4,56.5-4,45]) cylinder(h=6,d=5.5);
                translate([56.5-4,56.5-4,45]) cylinder(h=6,d=5.5);
            }
    
            // Welle
            translate([56.5 / 2, 56.5 / 2, 0]) union () {
                stepper_welle();
                translate([0,0,50.5]) cylinder(h=1.5, d=38);
            }
        }
        translate([0,0,71.5-(10+3)]) stepper_zahnrad();
    }
}

module stepper_small () {
    union () {
        
        //Grundkörper
        translate([-42.2 / 2, -42.2 / 2, 0]) union () {    
            cube([42.2,42.2,32]);
            translate([42.2 / 2, 42.2 / 2, 32]) cylinder(h=1.5, d=22); 
        }
        
        //Welle & Zahnrad
        translate([0,0,32+1.5]) {
            union () {
                    translate([0,0,18-3]) spur_gear(modul=gear_modul, tooth_number=10, width=3, bore=0);
                cylinder(h=18, d=5);
            }
        }
        
        //Befestigung
        translate ([-80/2, -20/2, 32-5]) difference () {
            cube([80, 20, 5]); 
            union () {
                translate([4, 20/2, 0]) cylinder(h=5, d=4) ;
                translate([80-4, 20/2, 0]) cylinder(h=5, d=4) ;
            }
        }  
    }
}

module large_gear () {
    difference () {
        cylinder(h = 3, d=gear_large_full_diameter);
        spur_gear(modul=gear_modul, tooth_number=gear_tooth_number_large, width=3, bore=0);
        cylinder(h = 3, d=(gear_large_full_diameter - 60));
    }
}

// Stepper
*color("red") translate([0,70,0]) stepper_small();

//Brett unten
*color("grey") translate([0,0,-12]) brett ();

// Top Gear
*color("yellow") translate([0,0,32+1.5+18-3]) large_gear ();