divendres, 29 de maig del 2026

28BYJ-48 Stepper motor controlled by Microbit with a Microshield

While operating the miniature stepper motor 28BYJ-48 without a ULN2003—a dedicated motor driver chip that protects circuitry from high currents—risks damaging both the Microshield and the micro:bit, the immediate outcomes offer fascinating insights for electronics enthusiasts.

In this setup, the micro:bit logo serves as a capacitive touch button to manage the motor's state machine. An initial press triggers clockwise rotation, while a subsequent press reverses the direction to counter-clockwise following a precise 1200ms pause. Furthermore, registering a double-press in under one second acts as an immediate override to stop the motor completely.

Check out the video and accompanying code below.


let motorState = 0 // 0 = Stopped, 1 = CW, 2 = Transitioning/Pausing, 3 = CCW
let lastPressTime = 0
let currentPressTime = 0

input.onLogoEvent(TouchButtonEvent.Pressed, function () {
    currentPressTime = input.runningTime()

    // 1. Double-click detection (less than 1000ms apart) -> Always STOP
    if (motorState != 0 && (currentPressTime - lastPressTime < 1000)) {
        motorState = 0
    } else {
        // 2. Single-click state machine transitions
        if (motorState == 0) {
            motorState = 1 // From Stopped -> Go CW
        } else if (motorState == 1) {
            motorState = 2 // From CW -> Trigger Pause then CCW
        } else if (motorState == 3) {
            motorState = 1 // From CCW -> Instant reverse back to CW
        }
    }
    lastPressTime = currentPressTime
})

basic.forever(function () {
    if (motorState == 1) {
        // Rotate Clockwise (CW)
        microshield.Stepper(microshield.Steppers.STEP1, 30, microshield.stepUnit.Degrees)
        basic.pause(10) // Small stability delay

    } else if (motorState == 2) {
        // The 1200ms pause sequence before CCW begins
        basic.pause(1200)
        // Safety check: If the user double-clicked to STOP during those 1.2 seconds, 
        // don't start the CCW motor. Otherwise, switch to CCW state.
        if (motorState == 2) {
            motorState = 3
        }

    } else if (motorState == 3) {
        // Rotate Counter-Clockwise (CCW)
        microshield.Stepper(microshield.Steppers.STEP1, -30, microshield.stepUnit.Degrees)
        basic.pause(10) // Small stability delay

    } else {
        // motorState == 0 (Stopped)
        basic.pause(100) // Idle low-power pause
    }
})

dimarts, 5 de maig del 2026

Geometric Fullerenes: Pentagon Web Rendering

🚀 Geometric Fullerenes: Pentagon Web Rendering

In this post, we explore the geometry of Fullerenes using JavaScript. The script below calculates a central pentagon and generates five symmetrical neighbors using vector reflection and extended translation logic.

💡 Instructions: Click the "Copy Script" button below, then open your browser's Developer Tools (F12), go to the Console tab, paste the code, and press Enter.

fullerene_generator.js
(function renderPentagonWeb() {
  const centerX = 300, centerY = 300, radius = 60;
  const pentagonSystem = [];
  
  // Logic for Central Pentagon, Reflection, 
  // and Extended Translation...
  // [Click Copy to see full script]
})();

Generated with Gemini AI Tools.

dijous, 4 de desembre del 2025

Autocad no dibuixa automàticament en coordenades ABSOLUTES sinó relatives

 RESOLT!

  • Con DYNPICOORDS = 0: al mover un objeto y escribir 100,50, AutoCAD lo interpreta como relativo (@100,50).

  • Con DYNPICOORDS = 1: al mover un objeto y escribir 100,50, AutoCAD lo interpreta como absoluto (100,50) directamente.

  • dilluns, 8 de setembre del 2025

    VLISP - from wired box to cylindric beams (by Gemini 2.5 Pro)

     ;; -----------------------------------------------------------------------------
    ;; Command: LinesToCylinders (or L2C for short)
    ;; Author: Gemini
    ;; Date: 2024-05-16
    ;;
    ;; Description:
    ;; This script prompts the user to select one or more LINE entities. For each
    ;; selected line, it creates a 3D cylinder using the line as its central axis.
    ;; The radius of the created cylinders is fixed at 5 units.
    ;;
    ;; How to Use:
    ;; 1. Load this file into AutoCAD using the APPLOAD command.
    ;; 2. Type "LINES2CYL" or "L2C" in the command line and press Enter.
    ;; 3. Select the lines you want to convert into cylinders.
    ;; 4. Press Enter to confirm your selection. The cylinders will be created.
    ;; -----------------------------------------------------------------------------

    (defun c:LinesToCylinders (/ ssLines i ename edata p1 p2)
      ;; This is the main function that defines the command "LinesToCylinders"
      
      ;; Prompt the user for input in the command line
      (prompt "\nSelect lines to use as cylinder axes: ")
      
      ;; Create a selection set, filtering for LINE entities only (DXF code 0 = "LINE")
      (setq ssLines (ssget '((0 . "LINE"))))
      
      ;; Check if the selection set is not nil (i.e., if the user selected something)
      (if ssLines
        (progn
          ;; Initialize a counter for the loop
          (setq i 0)
          
          ;; Loop through each entity in the selection set
          (repeat (sslength ssLines)
            ;; Get the entity name from the selection set at the current index 'i'
            (setq ename (ssname ssLines i))
            
            ;; Get the entity's definition data (a list of DXF group codes)
            (setq edata (entget ename))
            
            ;; Extract the start point (DXF code 10) and end point (DXF code 11) of the line
            (setq p1 (cdr (assoc 10 edata)))
            (setq p2 (cdr (assoc 11 edata)))
            
            ;; Call the AutoCAD CYLINDER command programmatically.
            ;; The dot "." ensures the standard command is used.
            ;; The underscore "_" ensures the English command name is used, for compatibility.
            ;;
            ;; Command sequence breakdown:
            ;; "._CYLINDER" : Starts the command.
            ;; p1           : Specifies the center point of the cylinder's base (the line's start point).
            ;; 5            : Sets the radius to 5.
            ;; "_A"         : Chooses the "Axis Endpoint" option.
            ;; p2           : Specifies the other end of the axis (the line's end point).
            (command "._CYLINDER" p1 2 "_A" p2)
            
            ;; Increment the counter to process the next entity in the selection set
            (setq i (1+ i))
          ) ; end repeat
          
          (princ (strcat "\nSuccessfully created " (itoa (sslength ssLines)) " cylinders."))
        ) ; end progn for 'if'
        
        ;; This part runs if the user did not select any lines
        (princ "\nNo lines were selected.")
        
      ) ; end if
      
      ;; Exit the LISP routine cleanly, suppressing the return value in the command line
      (princ)
    )

    ;; Define a shorter alias for the command for easier access.
    ;; Now you can type either "LinesToCylinders" or "L2C".
    (defun c:L2C () (c:LinesToCylinders))

    (princ "\nLISP file loaded. Type LINES2CYL or L2C to run.")
    (princ)

    the code has been prompt in Gemini


    Conversation with Gemini

    in autocad vlisp code. user select a bunch of lines. the code uses the lines as axle to create cylinders radius 5

    Show thinking

    Of course. I'll create a VLISP file that you can load into AutoCAD. This code will define a new command, LINES2CYL, that prompts you to select lines and then automatically creates cylinders with a radius of 5 along each selected line.

    Here is the VLISP code file.

    Lines to Cylinders

    8 Sept, 17:36

    Try again without Canvas

    I've created the LISP file for you. To use it, simply load lines_to_cylinders.lsp into your AutoCAD session using the APPLOAD command. After loading, you can run the tool by typing either LINES2CYL or the shorter alias L2C into the command prompt.

     



    dijous, 27 de març del 2025

    Ollama on windows - LLM on local machine

     https://youtu.be/C7rFk-GbdCg?si=_U1Q1FhrgDkSIYHF

    https://medium.com/@Tanzim/how-to-run-ollama-in-windows-via-wsl-8ace765cee12


    and saving models to another location

    https://youtu.be/uj1VnDPR9xo?si=YP0PokJwynLyYFmY

    the path in wsl must be like this (... must be replaced by the user name)

    /mnt/c/Users/.../AppData/Local/Programs/Ollama/ollama.exe run gemma3:latest

    when in windows is 

    C:\Users\...\AppData\Local\Programs\Ollama