// inslude the SPI library:
#include <SPI.h>
// set pin 10 as the slave select for the digital pot:
//const int slaveSelectPin = 10;
const int slaveSelectPin = 53; //WAS 10 on Arduino uno.
const int shutdownPin = 49; // was 7 on uno.
const int wiper0writeAddr = B00000000;
const int wiper1writeAddr = B00010000;
const int analogInPin_c = A5;
void setup() {
// set the slaveSelectPin as an output:
pinMode(slaveSelectPin, OUTPUT);
// initialize SPI:
SPI.begin();
pinMode (shutdownPin, OUTPUT);
// start with all the pots shutdown
digitalWrite(shutdownPin, LOW);
}
void loop() {
delay(2);
digitalWrite(slaveSelectPin, LOW);
digitalWrite(shutdownPin, HIGH); //Turn off shutdown THIS MAKE WRITEABLE OR DISABLE THIS CAN'T WRITE
delay(2);
// go through the six channels of the digital pot:
for (int channel = 0; channel < 6; channel++) {
//int channel = 0;
// for (int channel = 0; channel < 2; channel++) {
// change the resistance on this channel from min to max:
for (int level = 0; level < 255; level++) {
digitalPotWrite(channel, level);
delay(10);
}
// wait a second at the top:
delay(100);
// change the resistance on this channel from max to min:
for (int level = 0; level < 255; level++) {
digitalPotWrite(channel, 255 - level);
digitalPotWrite(wiper1writeAddr, 255 - level);
digitalPotWrite(wiper0writeAddr, 255 - level);
delay(2);
digitalWrite(shutdownPin, LOW); //Turn off shutdown THIS MAKE WRITEABLE OR DISABLE THIS CAN'T WRITE
delay(2);
delay(10);
}
}
}
void digitalPotWrite(int address, int value) {
// take the SS pin low to select the chip:
digitalWrite(slaveSelectPin, LOW);
// send in the address and value via SPI:
SPI.transfer(address);
SPI.transfer(value);
// take the SS pin high to de-select the chip:
digitalWrite(slaveSelectPin, HIGH);
}