Código para Análisis
2:22
mercurySwitchPin a algo como doorSensorPin (mantén el mismo número de pin o ajústalo según tu conexión).lastMercurySwitchState a lastDoorSensorState.mercurySwitchState por doorSensorState.doorSensorState == LOW (contactos abiertos) se activa la alarma (deteniendo el temporizador, encendiendo el LED rojo, mostrando mensaje de PELIGRO).Cpp
// Cambiar el nombre de la variable del interruptor de mercurio a sensor magnético const int doorSensorPin = 6; // Pin para el sensor magnético de puertas // Renombrar variable de estado previo int lastDoorSensorState = HIGH; ... void loop() { int buttonState = digitalRead(buttonPin); // Leer el sensor magnético en lugar del interruptor de mercurio int doorSensorState = digitalRead(doorSensorPin); unsigned long currentMillis = millis(); // Apagar pantalla si no hay interacción durante 25 segundos y el temporizador no está en marcha if (displayOn && !timerRunning && (currentMillis - lastInteractionTime > autoOffDelay)) { toggleDisplay(); } // Comprobar si el sensor magnético indica que los contactos se separaron (puerta abierta) if (doorSensorState == LOW && lastDoorSensorState == HIGH) { timerRunning = false; digitalWrite(RELE, LOW); digitalWrite(LED_RED, HIGH); if (displayOn) { display.clearDisplay(); display.setCursor(0, 0); display.setTextSize(1); display.print(F(" Puerta abierta")); display.setCursor(0, 16); display.print(F(" ¡PELIGRO!")); display.display(); } lastInteractionTime = currentMillis; } if (doorSensorState == HIGH && lastDoorSensorState == LOW) { digitalWrite(LED_RED, LOW); if (displayOn && !timerRunning) { displayQuestionWithImage(); } } lastDoorSensorState = doorSensorState; // ... El resto del código permanece igual ... }
Ready.
To get started, talk to Flux or create a New Document.
Reviews
Documents
Documents are markdown text files which describe project goals, capture details, or even simulation outputs.
Assets
No assets added.
Sorry Salmon Flux Capacitor
Properties
Properties describe core aspects of the project.
Pricing & Availability
Distributor | Qty 1 |
|---|
Controls
Welcome 👋
Flux helps you build PCBs faster with an AI teammate!
Create your account to collaborate, stay updated, fork your own version, and get instant answers from our AI agent.