finalized the AVR code, this may need debugging as we integrate SPI communication with the Pi