cewkomator/firmware/src/spindle.cpp

28 lines
600 B
C++

#include <AS5600.h>
#include <Wire.h>
#include "spindle.h"
AS5600 spindle(&Wire);
bool setupSpindle() {
if (!spindle.begin()) {
Serial.println("Could not initialize spindle encoder");
return false;
} else if (!spindle.detectMagnet()) {
Serial.println("Could not detect magnet");
return false;
} else if (spindle.magnetTooWeak()) {
Serial.println("Magnet too weak");
return false;
} else if (spindle.magnetTooStrong()) {
Serial.println("Magnet too strong");
return false;
}
return true;
}
uint16_t getSpindlePosition() {
return spindle.readAngle();
}