Initialization of SPI July 30, 2011 02:36PM |
Registered: 13 years ago Posts: 64 |
#include "SPI.h" // necessary library int del=0; // used for various delays word outputValue = 0; // a word is a 16-bit number byte data = 0; // and a byte is an 8-bit number void setup() { //set pin(s) to input and output pinMode(10, OUTPUT); SPI.begin(); // wake up the SPI bus. SPI.setBitOrder(MSBFIRST); } void loop() { for (int a=0; a<=4095; a++) { outputValue = a; digitalWrite(10, LOW); data = highByte(outputValue); data = 0b00001111 & data; data = 0b00110000 | data; SPI.transfer(data); data = lowByte(outputValue); SPI.transfer(data); digitalWrite(10, HIGH); delay(del); } delay(del+25); for (int a=4095; a>=0; --a) { outputValue = a; digitalWrite(10, LOW); data = highByte(outputValue); data = 0b00001111 & data; data = 0b00110000 | data; SPI.transfer(data); data = lowByte(outputValue); SPI.transfer(data); digitalWrite(10, HIGH); delay(del); } delay(del+25); }You are all familiar with the Five_D program I am sure. I just want to know where and how can I initialize this SPI routine in the main program