User Tools

Site Tools


3dprint:strobo-tumbling-cubes

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
3dprint:strobo-tumbling-cubes [2026/01/08 17:31] – created ivo3dprint:strobo-tumbling-cubes [2026/01/09 07:13] (current) – [Code] ivo
Line 1: Line 1:
 ====== Tumbling Cubes in Strobo lights ====== ====== Tumbling Cubes in Strobo lights ======
  
 +{{ :3dprint:strobo-tumbling-cubes.mp4|}}
  
 +
 +A hall sensor (outputting just high or low) measures the passing of four magnets to compute the angle.
 +
 +===== Files =====
 +==== 3D ====
 +    * {{ :3dprint:strobo-tumbling-cubes.scad|}} (OpenSCAD)
 +    * {{ :3dprint:motorbracket.fcstd |}}  (FreeCAD)
 +    * {{ :3dprint:pinwheel.fcstd |}} (FreeCAD)
 +    * {{ :3dprint:sensorbracket.fcstd |}} (FreeCAD)
 +    * {{ :3dprint:case.svg?linkonly |}} (Inkscape)
 +==== Code ====
 +Used an ESP32 (Doit DevBoard), with Platformio
 +<code cpp main.cpp>
 +#include <Arduino.h>
 +
 +#define LED 18
 +#define HALL 25
 +
 +volatile unsigned long ts[4]={0,0,0,0};
 +volatile int tsi = 0;
 +
 +void IRAM_ATTR recordTime() {
 +  tsi+=1;
 +  tsi&=3;
 +  ts[tsi] = micros();
 +}
 +
 +void setup() {
 +  pinMode(LED, OUTPUT);
 +  pinMode(HALL, INPUT);
 +  digitalWrite(LED, HIGH);
 +  Serial.begin(115200);
 +  attachInterrupt(digitalPinToInterrupt(HALL), recordTime, FALLING);
 +}
 +
 +double step = 0.25;
 +double golden = 1.0-(sqrt(5)-1)/2;
 +double nextAngle = golden;
 +
 +int lasti = 0;
 +bool full = false;
 +
 +double dts[4]={0,0,0,0};
 +
 +void loop() {
 +  if (tsi!=lasti) { // Tick has happend;
 +    lasti = tsi;
 +    if (tsi==0) {
 +      full = true;
 +    }
 +    if (full) {
 +      double angle = tsi*step;
 +      if (nextAngle>angle && nextAngle-angle<step) {
 +        double dt = ts[tsi]-ts[(tsi+3)&3];
 +        dts[tsi] = 0.8*dts[tsi]+0.2*dt;
 +        unsigned int w = dts[(tsi+1)&3]*(nextAngle-angle)/step;
 +        if (w<200000) {
 +          delayMicroseconds(w);
 +        }
 +        digitalWrite(LED, LOW);
 +        delayMicroseconds(200);
 +        digitalWrite(LED, HIGH);
 +        nextAngle += golden;
 +        if (nextAngle>1.0) {
 +          nextAngle -= 1.0;
 +        }
 +      }
 +    }
 +  }
 +}
 +
 +
 +</code>
 +==== Circuit ====
 +
 +Circuit for driving the 12V LED strip. Not very efficient and inverted logic, so it light up until the microcontroller has booted. But you do with what you have lying around...
 +
 +{{ :3dprint:circuit.svg |}}
3dprint/strobo-tumbling-cubes.1767893516.txt.gz · Last modified: by ivo