Exit Full View
Up

/Torch/CR2032Torch.foocad

CR2032Torch
FooCAD Source Code
import static uk.co.nickthecoder.foocad.layout.v1.Layout2d.*
import static uk.co.nickthecoder.foocad.layout.v1.Layout3d.*
/**
    Holds a "high power" led onto a CR2032 battery
    One leg of the LED is bent over to touch the side of the batter, and
    the other remains flat, touching the top of the battery.

    In my experience, this works fine without a resistor.
*/
class CR2032Torch : Model {
    
    var ledSize = 9.5
    var ledHeight = 3.0
    var batterySize = 22.0
    var batteryHeight = 3.5
    var thickness = 0.8

    @Custom
    var quantity = 10

    fun plain() : Shape3d {

        val foo = Square( 11, batterySize + 3 )
            .roundAllCorners(1)
            .center()

        val hole = Cylinder.hole(6.2,3)
            .centerXY()
            .translateZ(2)

        val indent = Cylinder.hole(ledHeight, ledSize/2 )
            .translateZ(batteryHeight+1-0.01)

        val slot = Cube( 20, batterySize, batteryHeight )
            .centerXY()
            .translateZ(1)

        val groove = Cube( 13, 3, ledHeight *2 )
            .centerXY()
            .translate(2,0,1+batteryHeight-0.01)

        val battery = Cylinder( batteryHeight, batterySize/2 )
            .translate(6.5, 0, 1)
            .color( "Green" )

        // Helps fit the LED, by leaving space for the bent over pin.
        val nibble = Cube( 3,3,20 ).center()
            .translateX(-5)

        val envelope = Cylinder( 20, batterySize/2 + 2 )
            .center()
            .translate(6.5, 0, 0)

        val bar = foo.extrude( batteryHeight + thickness*2 + ledHeight )

        return (bar/envelope).remove(slot + hole + groove + indent + nibble)
    }

    override fun build() : Shape3d {
        val one = plain().rotateY(90).toOriginZ()

        return one.tileX(quantity,1)
    }
}