#include <Keypad.h>
#include <Wire.h>
#include <Adafruit_MCP4725.h>
Adafruit_MCP4725 dac;
/// declarer paramètres keyboard
int dt = 1;
float tension_touche;
const byte ROWS = 2;
const byte COLS = 2;
uint16_t dacValue;
// tension minimum C0 et increment par demi ton du keyboard
int Vmin = 1;
float dV =1.0/12.0;
/// touches du keyboard
char hexaKeys[ROWS][COLS] = {
{'A', 'B'},
{'C', 'D'},
};
byte colPins[COLS] = {6, 7};
byte rowPins[ROWS] = {2, 3};
/// mapping keyboard avec lignes et colonnes
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
/// definition pin GATE, VELOCITY et OFFSET CV (?)
byte gatePin = 13;
void setup() {
Serial.begin(9600);
pinMode(gatePin, OUTPUT);
digitalWrite(gatePin, LOW);
// For Adafruit MCP4725A1 the address is 0x62 (default) or 0x63 (ADDR pin tied to VCC)
// For MCP4725A0 the address is 0x60 or 0x61
// For MCP4725A2 the address is 0x64 or 0x65
dac.begin(0x60); // L'adresse I2C du MCP4725 peut varier, assurez-vous de consulter la documentation du MCP4725
}
void loop() {
/// Detecter touche du keyboard enfoncée et envoyer la bonne tension dans le DAC en fonction de la note
char key = customKeypad.getKey();
if (key) {
digitalWrite(gatePin, HIGH);
Serial.println("ON");
switch (key) {
case 'A':
tension_touche = Vmin + 0*dV;
dacValue = round(tension_touche*(4095/5));
dac.setVoltage(dacValue, false);
Serial.print(dacValue);
break;
case 'B':
tension_touche = Vmin + 1*dV;
dacValue = round(tension_touche*(4095/5));
dac.setVoltage(dacValue, false);
Serial.print(dacValue);
break;
case 'C':
tension_touche = Vmin + 2*dV;
dacValue = round(tension_touche*(4095/5));
dac.setVoltage(dacValue, false);
Serial.print(dacValue);
break;
case 'D':
tension_touche = Vmin + 3*dV;
dacValue = round(tension_touche*(4095/5));
dac.setVoltage(dacValue, false);
Serial.print(dacValue);
break;
}
}
else{
digitalWrite(gatePin, LOW);
}
}