0
mirror of https://github.com/Mister-Industries/tinyCore.git synced 2026-08-31 16:16:31 +00:00
Files
2025-03-22 16:07:53 -06:00

60 lines
1.6 KiB
C++

// Basic demo for configuring the MCP4728 4-Channel 12-bit I2C DAC
#include <Adafruit_MCP4728.h>
#include <Wire.h>
Adafruit_MCP4728 mcp;
void setup(void) {
Serial.begin(115200);
while (!Serial)
delay(10); // will pause Zero, Leonardo, etc until serial console opens
Serial.println("Turning on I2C Devices...");
pinMode(6, OUTPUT);
digitalWrite(6, HIGH);
Serial.println("Starting I2C initialization...");
Wire.begin(3, 4);
delay(100); // Give I2C time to stabilize
Serial.println("Adafruit MCP4728 test!");
// Try to initialize!
if (!mcp.begin()) {
Serial.println("Failed to find MCP4728 chip");
while (1) {
delay(10);
}
}
}
void loop() {
mcp.setChannelValue(MCP4728_CHANNEL_A, 100);
mcp.setChannelValue(MCP4728_CHANNEL_B, 0);
mcp.setChannelValue(MCP4728_CHANNEL_C, 0);
mcp.setChannelValue(MCP4728_CHANNEL_D, 0);
delay(10);
mcp.setChannelValue(MCP4728_CHANNEL_A, 0);
mcp.setChannelValue(MCP4728_CHANNEL_B, 100);
mcp.setChannelValue(MCP4728_CHANNEL_C, 0);
mcp.setChannelValue(MCP4728_CHANNEL_D, 0);
delay(10);
mcp.setChannelValue(MCP4728_CHANNEL_A, 0);
mcp.setChannelValue(MCP4728_CHANNEL_B, 0);
mcp.setChannelValue(MCP4728_CHANNEL_C, 100);
mcp.setChannelValue(MCP4728_CHANNEL_D, 0);
delay(10);
mcp.setChannelValue(MCP4728_CHANNEL_A, 0);
mcp.setChannelValue(MCP4728_CHANNEL_B, 0);
mcp.setChannelValue(MCP4728_CHANNEL_C, 0);
mcp.setChannelValue(MCP4728_CHANNEL_D, 100);
delay(10);
mcp.setChannelValue(MCP4728_CHANNEL_A, 0);
mcp.setChannelValue(MCP4728_CHANNEL_B, 0);
mcp.setChannelValue(MCP4728_CHANNEL_C, 0);
mcp.setChannelValue(MCP4728_CHANNEL_D, 0);
delay(2);
}