/* file: SwitchSimple.scad * author: Christophe Delannoy * creation: 2020/07/07 */ /* common params */ radius = 3; length = 30; high = 2; /* FZ31-3H */ numPlots = 4; // L/0/1/2 plotNames = ["L", "0", "1", "2"]; /* connections, standard (compare to the BT7000 Service Manual) */ numPositions = 3; // sizeoff(positionData) positionData = [ [1, 1, 0, 0], // L-1 [1, 0, 1, 0], // L-2 [1, 0, 0, 1] // L-3 ]; numSegments = numPositions*numPlots; /* microsteps: * we have XX microsteps: * 0: just half-move to the new position; added connections not drawn * 1: just full-move to the new position; added connections not drawn * 2, 3,...: make the added Connection appear, dealing with Alpha (transparency) */ //numMicrosteps = 8; // if anim numMicrosteps = 1; // animation; for setup, use: theTime=0.1, theTime=0.2, ... theTime = $t; //theTime = 0.53; // if not animating stepTime = round(theTime*360); // translate from [0..1[ to [0..360[ // V1 //stepPosition = theTime * numPositions; // [0..numPositions[ //microstep = (theTime * numSegments) % 4; // [0..numMicrosteps[ // V2 stepPosition = floor(stepTime / (360/numPositions) ); // remainder for the division; in [0..(360/numPositions)[, i.e. [0..60[ microstep_Temp = stepTime - stepPosition*(360/numPositions); // low it to [0..numMicrosteps[ microstep = round(microstep_Temp * numMicrosteps / 60); /// RUN: drawAllPlots(stepPosition); //drawSegment(270, alpha=1.0); // for test; try: 0, 90, 180, 270 //drawAllSegments(2, 0); // for test; try: 0, 1, 2 (in 0..", microstep), size=8, halign = "center"); */ // TEST for microStep module testSteps() { numFrames = (numPositions*numMicrosteps); // this paramerter would be the one for Animation render echo("numFrames: ", numFrames); for(timeIndex = [0:numFrames-1]) { stepTime = timeIndex*360/numFrames; stepPosition = floor(stepTime / (360/numPositions) ); // remainder (in [0..(360/numPositions)[) microstep_Temp = stepTime - stepPosition*(360/numPositions); microstep = floor(microstep_Temp * numMicrosteps / 60); echo("Step ([position, micro]: [", stepPosition, microstep, "]"); } } //testSteps(); module drawPlot(angle, plotName, plotColor="Gold") { color(plotColor) rotate([0, 0, 180-45-angle]) { translate([1, 0, 0]) // for the gap difference() { translate([length, -radius, 0]) cube([radius+radius, radius+radius, high]); // hole: add -1/+2 to ensure diff() success translate([length, 0, -1]) cylinder(h=high+2, r=radius); } // draw the plot Name: translate([50, 0, 2]) rotate([0, 0, -180+45+angle]) linear_extrude(high) text(plotName, halign = "center", valign = "center"); } } module drawAllPlots(position) { dataForPosition = positionData[position]; //echo("drawAllPlots: dataForPosition = ", dataForPosition); //drawPlot(0, "L"); drawPlot(90, "1"); drawPlot(180, "2"); drawPlot(270, "3"); for(plotIndex = [0:numPlots-1]) { connected = dataForPosition[plotIndex]; plotColor = connected ? "Yellow" : "Goldenrod"; drawPlot(plotIndex*90, plotNames[plotIndex], plotColor); } } module drawSegment(angle, alpha=1.0) { echo("drawSegment called with angle: ", angle); color("DarkRed", alpha) rotate([0, 0, 180-45-angle]) hull(){ // not good drawing if alpha, use union() ? todo spline->extrude // hull(à is OK // center: cylinder(h=high, r=radius); // segment: translate([0, -radius, 0]) cube([length, radius+radius, high]); // extremities: translate([length, 0, 0]) cylinder(h=high, r=radius); } } /// param: position is the current rotation for the knob (from 0 to 3) /// param: microStep is the intermediate rotation for the knob (e.g. when position param is 0, drawn position is beetween 0 and 1) module drawAllSegments(position, microStep) { // Draw the Position value: translate([0, -50, 0]) linear_extrude(high) text(str("Position: ",position), size=8, halign = "center"); positionIndex = position; //for(positionIndex = [0:numPositions-1])//:numPositions-1 { dataForPosition = positionData[positionIndex]; echo("drawAllSegments: dataForPosition =", positionIndex, " => ", dataForPosition); for(plotIndex = [0:numPlots-1])// :numPlots-1] { // segmentIndex = -plotIndex*numPositions + positionIndex; //segmentIndex = positionIndex*numPositions + plotIndex; drawable = dataForPosition[plotIndex]; // echo("segmentIndex/numSegments/drawable: ", segmentIndex, numSegments, drawable); echo("plotIndex/drawable: ", plotIndex, drawable); /* segmentAlpha = (positionIndex0) ? angleAtPos0 + position*(360/numSegments) : // move only with the half angle angleAtPos0 + position*(360/numSegments)-180/numSegments; // for complexe use angleAtPos0, for simple use angleAtPos0 //if(plotIndex==0) drawSegment(angleAtPos0, 1); //else // drawSegment(angleWithPos, 1); } } } }