65 min en Wokwi. Sin hardware. Proyecto base ya armado y funcionando; el potenciómetro simula el sensor de temperatura del motor.
// Termostato de ventilador — MadRams, Sesión 2
const int PIN_SENSOR = 34; // potenciómetro
const int PIN_VENT = 2; // LED = ventilador
const float T_ENCIENDE = 95.0; // °C
const float T_APAGA = 88.0; // °C
bool ventiladorEncendido = false;
float leerTemperatura() {
int crudo = analogRead(PIN_SENSOR); // 0..4095
return 60.0 + (crudo * (130.0 - 60.0) / 4095.0); // 60..130 °C
}
void setup() {
Serial.begin(115200);
pinMode(PIN_VENT, OUTPUT);
}
void loop() {
float t = leerTemperatura();
if (!ventiladorEncendido && t >= T_ENCIENDE) {
ventiladorEncendido = true;
} else if (ventiladorEncendido && t <= T_APAGA) {
ventiladorEncendido = false;
}
digitalWrite(PIN_VENT, ventiladorEncendido ? HIGH : LOW);
Serial.print("T=");
Serial.print(t, 1);
Serial.print(" C ventilador=");
Serial.println(ventiladorEncendido ? "ON" : "OFF");
delay(200);
}
En parejas, sin correr nada. Tres respuestas por escrito:
Correr el proyecto Wokwi. Subir el potenciómetro lento hasta el tope y bajarlo igual de lento. Anotar:
ventiladorEncendido: quién la cambia y cuándo. Dibujar los dos estados y las dos flechas.T_ENCIENDE = T_APAGA = 90.0. Correr y dejar el potenciómetro justo ahÃ. Describir el chattering en el monitor serial y por qué destruirÃa un relevador real.delay(200) a delay(2000). ¿Qué se pierde? Relacionarlo con frecuencia de muestreo.else if y no dos if independientes?