// https://wokwi.com/projects/380733829667456001
// el modulo DAC no funciona en el simulador
#define PinADC 34
#define DACPin 25
void setup() {
//set the resolution to 12 bits (0-4096)
analogReadResolution(12);
// voltage full-range 150mV - 3100 mV
analogSetAttenuation(ADC_11db); // ADC_0db, ADC_2_5db, ADC_6db, ADC_11db
// DAC channel 1 is attached to GPIO25, DAC channel 2 is attached to GPIO26
// acepta valores de 0 a 255 -> Vout = 0 a 3.3v
Serial.begin(115200);
Serial.printf("Ejemplo de configuracion y uso ADC-DAC \n");
}
void loop() {
int adcVal = analogRead(PinADC); // leemos el valor del ADC
float voltage = adcVal / 4095.0 * 3.3; // conversion de tension ideal
int dacVal = 255.0 * (voltage / 3.3); // tensión de salida en el DAC
dacWrite(DACPin, dacVal); // ilumina más o menos el LED
Serial.printf("ADC Val: %d, DAC Val: %d, Voltage: %1.3f V \n", adcVal,dacVal, voltage);
delay(1000);
}