Working Magnetometer code

Code can sense direction, can be tuned to 'event' duration using the
window paramater, and the threshold paramater.