3dprint:strobo-tumbling-cubes
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| 3dprint:strobo-tumbling-cubes [2026/01/08 18:10] – ivo | 3dprint:strobo-tumbling-cubes [2026/01/09 07:13] (current) – [Code] ivo | ||
|---|---|---|---|
| Line 2: | Line 2: | ||
| {{ : | {{ : | ||
| + | |||
| + | |||
| + | A hall sensor (outputting just high or low) measures the passing of four magnets to compute the angle. | ||
| ===== Files ===== | ===== Files ===== | ||
| - | | + | ==== 3D ==== |
| + | | ||
| + | * {{ : | ||
| + | * {{ : | ||
| + | * {{ : | ||
| + | * {{ : | ||
| + | ==== Code ==== | ||
| + | Used an ESP32 (Doit DevBoard), with Platformio | ||
| + | <code cpp main.cpp> | ||
| + | #include < | ||
| + | |||
| + | #define LED 18 | ||
| + | #define HALL 25 | ||
| + | |||
| + | volatile unsigned long ts[4]={0, | ||
| + | volatile int tsi = 0; | ||
| + | |||
| + | void IRAM_ATTR recordTime() { | ||
| + | tsi+=1; | ||
| + | tsi& | ||
| + | ts[tsi] = micros(); | ||
| + | } | ||
| + | |||
| + | void setup() { | ||
| + | pinMode(LED, | ||
| + | pinMode(HALL, | ||
| + | digitalWrite(LED, | ||
| + | Serial.begin(115200); | ||
| + | attachInterrupt(digitalPinToInterrupt(HALL), | ||
| + | } | ||
| + | |||
| + | double step = 0.25; | ||
| + | double golden = 1.0-(sqrt(5)-1)/ | ||
| + | double nextAngle = golden; | ||
| + | |||
| + | int lasti = 0; | ||
| + | bool full = false; | ||
| + | |||
| + | double dts[4]={0, | ||
| + | |||
| + | void loop() { | ||
| + | if (tsi!=lasti) { // Tick has happend; | ||
| + | lasti = tsi; | ||
| + | if (tsi==0) { | ||
| + | full = true; | ||
| + | } | ||
| + | if (full) { | ||
| + | double angle = tsi*step; | ||
| + | if (nextAngle> | ||
| + | double dt = ts[tsi]-ts[(tsi+3)& | ||
| + | dts[tsi] = 0.8*dts[tsi]+0.2*dt; | ||
| + | unsigned int w = dts[(tsi+1)& | ||
| + | if (w< | ||
| + | delayMicroseconds(w); | ||
| + | } | ||
| + | digitalWrite(LED, | ||
| + | delayMicroseconds(200); | ||
| + | digitalWrite(LED, | ||
| + | nextAngle += golden; | ||
| + | if (nextAngle> | ||
| + | nextAngle -= 1.0; | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | |||
| + | |||
| + | </ | ||
| + | ==== 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/strobo-tumbling-cubes.1767895854.txt.gz · Last modified: by ivo
