AS5040/5045 library for arduino
This is something I should have written like five years ago. I’m making an electronic ignition controller for an old sportscar, and need to make a lot of calls to an AS5040 as a throttle position sensor. My old code works, but wouldn’t it be nice to have the rotary encoder work, in code, the way an LCD does? So I wrote a library.
Now I — or you — can write code like:
#include “AS5040.h”
AS5040 my5040(2,3,4); // data, clock, chip select pins
int measured_degrees;
measured_degrees = my5040.encoder_degrees();
WAAAAY easier and cleaner-looking than the previous pile of code.
So I’ve written encoder_value, giving the raw value (out of 1024 bits for the AS5040 and 4096 bits for the 5045), encoder_degrees (calculated from previous) and encoder_error, which returns a long int containing the errorcodes, but also populates a struct containing all the errors the chip reports so you can check which is occurring without having to unpack the error number.
Library and demo arduino code here: http://madscientisthut.com/forum_php/viewtopic.php?f=11&t=17 along with some instructions on how to install a new library, in case you haven’t done this.