This is very cool, but I was surprised to see what seems like an obvious bug in your code. In the buzzer() function, it looks like you were trying to use "buzz_prev" to optimize away extra writes of 0 when no magnetic field is detected. However, buzz_prev will never get reset because line 57, which sets it to zero, will only be executed if (!buzz_prev), that is, if it's already zero.