Changed slaveSelectPin to a const int rather than hard coded number.

This commit is contained in:
Tom Igoe 2010-08-13 02:45:20 +00:00
parent 645d9cac85
commit ecb26ec6dc
1 changed files with 8 additions and 4 deletions

View File

@ -30,9 +30,13 @@
// inslude the SPI library: // inslude the SPI library:
#include <SPI.h> #include <SPI.h>
void setup() {
// set pin 10 as the slave select for the digital pot: // set pin 10 as the slave select for the digital pot:
pinMode (10, OUTPUT); const int slaveSelectPin = 10;
void setup() {
// set the slaveSelectPin as an output:
pinMode (slaveSelectPin, OUTPUT);
// initialize SPI: // initialize SPI:
SPI.begin(); SPI.begin();
} }
@ -58,10 +62,10 @@ void loop() {
int digitalPotWrite(int address, int value) { int digitalPotWrite(int address, int value) {
// take the SS pin low to select the chip: // take the SS pin low to select the chip:
digitalWrite(10,LOW); digitalWrite(slaveSelectPin,LOW);
// send in the address and value via SPI: // send in the address and value via SPI:
SPI.transfer(address); SPI.transfer(address);
SPI.transfer(value); SPI.transfer(value);
// take the SS pin high to de-select the chip: // take the SS pin high to de-select the chip:
digitalWrite(10,HIGH); digitalWrite(slaveSelectPin,HIGH);
} }