// inslude the SPI library:
#include <SPI.h>
const int slaveSelectPin = 10; // set pin 10 as the slave select
const int clrPin=9; //set pin 9 for clear DAC >> optional
int max_value=4095; // max value for DAC
int min_value=0; //min value dor DAC
int value;
int AByte = 0;
int command = 0b000000000000; // 0100 Load input and DAC registers from shift register; DAC output updated.
int data = 0b111111111111; // desired DAC output.
int commandPlusData = command | data;
void setup() {
Serial.begin(9600);
// set the slaveSelectPin as an output:
pinMode (slaveSelectPin, OUTPUT);
digitalWrite (slaveSelectPin, HIGH);
pinMode (clrPin,OUTPUT);
digitalWrite (clrPin, HIGH); // clear DAC
// initialize SPI:
SPI.begin();
}
void loop() {
SPI.transfer (highByte (commandPlusData));
SPI.transfer (lowByte (commandPlusData));
digitalWrite (slaveSelectPin, HIGH);
delay(80);
}