moved SPI output to a function