1
0
mirror of https://github.com/arduino/Arduino.git synced 2024-12-01 12:24:14 +01:00

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

View File

@ -30,9 +30,13 @@
// inslude the SPI library: // inslude the SPI library:
#include <SPI.h> #include <SPI.h>
// set pin 10 as the slave select for the digital pot:
const int slaveSelectPin = 10;
void setup() { void setup() {
// set pin 10 as the slave select for the digital pot: // set the slaveSelectPin as an output:
pinMode (10, 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);
} }