42 lines
907 B
C++
42 lines
907 B
C++
// Basic demo for configuring the MCP4728 4-Channel 12-bit I2C DAC
|
|
#include <Adafruit_MCP4728.h>
|
|
#include <Wire.h>
|
|
|
|
Adafruit_MCP4728 mcp;
|
|
|
|
float xlog = 0.5;
|
|
float r = 3.783423;
|
|
|
|
void setup(void) {
|
|
Serial.begin(115200);
|
|
while (!Serial)
|
|
delay(10); // will pause Zero, Leonardo, etc until serial console opens
|
|
|
|
Serial.println("Adafruit MCP4728 test!");
|
|
|
|
// Try to initialize!
|
|
if (!mcp.begin(0x64)) {
|
|
Serial.println("Failed to find MCP4728 chip");
|
|
while (1) {
|
|
delay(10);
|
|
}
|
|
}
|
|
|
|
mcp.setChannelValue(MCP4728_CHANNEL_A, 4095);
|
|
mcp.setChannelValue(MCP4728_CHANNEL_B, 2048);
|
|
mcp.setChannelValue(MCP4728_CHANNEL_C, 1024);
|
|
mcp.setChannelValue(MCP4728_CHANNEL_D, 0);
|
|
|
|
|
|
}
|
|
|
|
|
|
void loop() {
|
|
int pot = analogRead(A0);
|
|
r = (float)pot / 1024.0 + 3.0;
|
|
xlog = r * xlog * (1 - xlog);
|
|
int cv = round(xlog * 4095.0);
|
|
mcp.setChannelValue(MCP4728_CHANNEL_A, cv);
|
|
// delay(100);
|
|
}
|