#include <SPI.h>
void setup() {
// pin 10 is the slave select for the digital pot
pinMode( SS, OUTPUT); // set the slaveSelectPin as an output
digitalWrite(SS, HIGH); // take the SS pin high to de-select the chip
// MISO input needs to be ;ulled up for the AD5142
pinMode( MISO, INPUT_PULLUP);
SPI.begin(); // initialize SPI
// set SPI speed to 500 kHertz, MSB, NORMAL LOW CLK and FALLING EDGE
SPI.beginTransaction (SPISettings (500000, MSBFIRST, SPI_MODE1));
// make sure the control register is correct:
digitalWrite(SS, LOW);// take the SS pin low to select the chip
SPI.transfer(0b11010000); // Copy serial register data to control register command 16
SPI.transfer(0b00000011); // D2= 0 = potentiometer mode, D1=1 = enables EEPROM programing, D0=1 = allow update of wiper position
digitalWrite(SS, HIGH); // take the SS pin high to de-select the chip
}
void loop() {
writeOne();
delay(10);
}
void writeOne(){
digitalWrite(SS, LOW);// take the SS pin low to select the chip
SPI.transfer(0b00010000); // command 1= set pot, pot selected= 0
SPI.transfer(0b00000001); // pot value= 1
digitalWrite(SS, HIGH); // take the SS pin high to de-select the chip
}