#include #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-angle1.0) { nextAngle -= 1.0; } } } } }