Program Source “DAC_0515.ino”
1#include <SPI.h> 2#include <MCP_DAC.h> 3 4#define PIN_CS 8 5#define PIN_SCK 9 6#define PIN_SDI 10 7 8MCP4821 McpDac(PIN_SDI, PIN_SCK); 9 10void setup() { 11 Serial.begin(9600); 12 13 McpDac.begin(PIN_CS); 14 McpDac.setGain(2); 15 delayMicroseconds(100); 16} 17 18void loop() { 19 static int t = 0; 20 t ^= 1; 21 McpDac.analogWrite(t * 4095); 22 delayMicroseconds(1); 23 Serial.print(t); 24 Serial.print(" "); 25 Serial.println(analogRead(A0)); 26 delay(1000); 27}