arduino-modular/Scales/Scales.ino

43 lines
937 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;
int tuning[13];
int scale[] = { 0, 4, 7, 9, 12 };
float voltrange = 5.0; // measured this, probably not accurate
float octave = 4096.0 / voltrange; // number of DAC steps in an octave
void setup(void) {
Serial.begin(115200);
while (!Serial)
delay(10); // will pause Zero, Leonardo, etc until serial console opens
if (!mcp.begin(0x64)) {
Serial.println("Failed to find MCP4728 chip");
while (1) {
delay(10);
}
Serial.println("MCP4728 initialised");
}
Serial.println(octave);
float n0 = 2048;
for( int i = 0; i < 13; i++ ) {
tuning[i] = round(n0 + octave * (float)i / 12);
Serial.println(tuning[i]);
}
}
void loop() {
for( int i = 0; i < 5; i++ ) {
mcp.setChannelValue(MCP4728_CHANNEL_A, tuning[scale[i]]);
delay(200);
}
}