// Basic demo for configuring the MCP4728 4-Channel 12-bit I2C DAC #include #include Adafruit_MCP4728 mcp; // idea behind this - sequence a cloud of gate events // 1 3 5 7 hexany log2 int bpm = 135; float beat_s = 60.0 / (float)bpm; int beat_m = round(1000.0 * beat_s); float mod_b = 3.141592653589793 / 4.0; int gate = 0; int gatel = 1000; int tick = 16; long init_t; float p_gate = 0.0; 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"); } init_t = millis(); mcp.setChannelValue(MCP4728_CHANNEL_B, 0); } void loop() { if( gate > 0 ) { gate--; if( gate == 0 ) { mcp.setChannelValue(MCP4728_CHANNEL_B, 0); } } else { long now = millis(); long mod_t = now - init_t; tick--; if( tick == 0 ) { tick = 16; p_gate = sin(mod_b * (float)mod_t / (float)beat_m); } if( (float)random(10000) / 100.0 < abs(p_gate)) { mcp.setChannelValue(MCP4728_CHANNEL_B, 4095); gate = gatel; } } }