arduino-modular/TestFour/TestFour.ino

42 lines
957 B
Arduino
Raw Normal View History

2023-12-09 22:18:00 +00:00
// 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() {
for( int i = 0; i < 1024; i++ ) {
mcp.setChannelValue(MCP4728_CHANNEL_A, i);
mcp.setChannelValue(MCP4728_CHANNEL_B, i * 2);
mcp.setChannelValue(MCP4728_CHANNEL_C, i * 3);
mcp.setChannelValue(MCP4728_CHANNEL_D, i * 4);
}
}