#include <TM1637Display.h>
// Pines
const int washPin = 9; // Pin PWM para el motor (lavado)
const int curePin = 10; // Pin para la tira LED UV (curado)
const int buttonMode = 2; // Botón para seleccionar función
const int buttonSpeed = 3; // Botón para seleccionar velocidad o intensidad
const int buttonStartPause = 5; // Botón para Start/Pause
const int buzzerPin = 11; // Pin para el buzzer
// LED Control
const int ledWash = 6; // LED para función de lavado
const int ledCure = 7; // LED para función de curado
const int ledLow = 8; // LED para velocidad Lenta
const int ledNormal = 12; // LED para velocidad Normal
const int ledHigh = 13; // LED para velocidad Alta
// Pines para TM1637
const int CLK = 14; // Pin de reloj
const int DIO = 15; // Pin de datos
// Variables
int mode = 0; // 0 = Motor, 1 = LED UV
int speed = 0; // 0 = Lento, 1 = Normal, 2 = Rápido
int uvIntensity = 0; // 0-255 para la intensidad del LED UV
unsigned long timerDuration = 5 * 60 * 1000; // 5 minutos en milisegundos
unsigned long timerStart = 0;
bool timerActive = false;
bool isRunning = false; // Estado de ejecución
// Estado de los botones
struct ButtonState {
bool lastState;
bool currentState;
};
ButtonState buttonModeState = {LOW, LOW};
ButtonState buttonSpeedState = {LOW, LOW};
ButtonState buttonStartPauseState = {LOW, LOW};
unsigned long lastDebounceTime = 0; // Tiempo de rebote
const unsigned long debounceDelay = 50; // Tiempo de rebote
// Inicialización de la pantalla TM1637
TM1637Display display(CLK, DIO);
void setup() {
pinMode(washPin, OUTPUT); // Pin para el motor
pinMode(curePin, OUTPUT); // Pin para la tira LED UV
pinMode(buttonMode, INPUT_PULLUP); // Usar pull-up interno
pinMode(buttonSpeed, INPUT_PULLUP); // Usar pull-up interno
pinMode(buttonStartPause, INPUT_PULLUP); // Usar pull-up interno
pinMode(ledWash, OUTPUT); // LED para función de lavado
pinMode(ledCure, OUTPUT); // LED para función de curado
pinMode(ledLow, OUTPUT); // LED para velocidad Lenta
pinMode(ledNormal, OUTPUT); // LED para velocidad Normal
pinMode(ledHigh, OUTPUT); // LED para velocidad Alta
pinMode(buzzerPin, OUTPUT); // Pin para el buzzer
digitalWrite(washPin, LOW);
digitalWrite(curePin, LOW);
display.setBrightness(0x0f); // Máxima luminosidad
display.clear(); // Limpiar la pantalla
}
void loop() {
// Leer el estado de los botones
readButton(buttonMode, buttonModeState, mode, 2);
readButtonSpeed(buttonSpeed, buttonSpeedState);
readButton(buttonStartPause, buttonStartPauseState, isRunning);
// Controlar el motor y la tira LED UV si está en ejecución
controlDevices();
// Manejo del temporizador
if (timerActive) {
handleTimer();
}
}
void readButton(int buttonPin, ButtonState &buttonState, int &variable, int maxValue) {
bool reading = digitalRead(buttonPin);
if (reading != buttonState.lastState) {
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay) {
if (reading == LOW && buttonState.currentState == HIGH) { // Cambio a LOW
variable = (variable + 1) % maxValue; // Ciclar entre valores
updateFunctionLEDs();
updateSpeedLEDs();
}
}
buttonState.currentState = reading;
buttonState.lastState = reading;
}
void readButtonSpeed(int buttonPin, ButtonState &buttonState) {
bool reading = digitalRead(buttonPin);
if (reading != buttonState.lastState) {
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay) {
if (reading == LOW && buttonState.currentState == HIGH) { // Cambio a LOW
if (mode == 0) {
// Cambiar la velocidad del motor
speed = (speed + 1) % 3; // Ciclar entre 0, 1, 2
} else {
// Cambiar la intensidad del LED UV
uvIntensity = (uvIntensity + 85) % 340; // Ciclar entre 0, 85, 170, 255
}
updateSpeedLEDs();
}
}
buttonState.currentState = reading;
buttonState.lastState = reading;
}
void controlDevices() {
if (isRunning) {
if (mode == 0) { // Motor
int motorSpeed = getMotorSpeed();
analogWrite(washPin, motorSpeed); // Controlar el motor
digitalWrite(ledWash, HIGH); // Encender LED de lavado
digitalWrite(ledCure, LOW); // Apagar LED de curado
} else { // LED UV
analogWrite(curePin, uvIntensity); // Controlar la intensidad del LED UV
analogWrite(washPin, 38); // Motor a 15% (255 * 0.15 ≈ 38)
digitalWrite(ledWash, LOW); // Apagar LED de lavado
digitalWrite(ledCure, HIGH); // Encender LED de curado
}
} else {
// Apagar todo si está en pausa
digitalWrite(washPin, LOW); // Apagar motor
digitalWrite(curePin, LOW); // Apagar tira LED UV
digitalWrite(ledWash, LOW); // Apagar LED de lavado
digitalWrite(ledCure, LOW); // Apagar LED de curado
}
}
void handleTimer() {
unsigned long elapsed = millis() - timerStart;
if (elapsed >= timerDuration) {
timerActive = false; // Detener temporizador
isRunning = false; // Detener ejecución
digitalWrite(washPin, LOW); // Apagar motor
digitalWrite(curePin, LOW); // Apagar tira LED UV
display.clear(); // Limpiar la pantalla
tone(buzzerPin, 1000, 500); // Sonar el buzzer durante 500 ms
} else {
// Calcular el tiempo restante
unsigned long remaining = (timerDuration - elapsed) / 1000; // En segundos
display.showNumberDec(remaining, true); // Mostrar el tiempo restante en la pantalla
}
}
int getMotorSpeed() {
switch (speed) {
case 0: return 38; // Lento (15%)
case 1: return 127; // Normal (50%)
case 2: return 255; // Rápido (100%)
default: return 0; // Apagar
}
}
void updateFunctionLEDs() {
digitalWrite(ledWash, mode == 0 ? HIGH : LOW); // LED para lavado
digitalWrite(ledCure, mode == 1 ? HIGH : LOW); // LED para curado
}
void updateSpeedLEDs() {
digitalWrite(ledLow, mode == 0 && speed == 0 ? HIGH : LOW); // LED para velocidad Lenta
digitalWrite(ledNormal, mode == 0 && speed == 1 ? HIGH : LOW); // LED para velocidad Normal
digitalWrite(ledHigh, mode == 0 && speed == 2 ? HIGH : LOW); // LED para velocidad Alta
digitalWrite(ledLow, mode == 1 && uvIntensity == 85 ? HIGH : LOW); // LED para intensidad Baja
digitalWrite(ledNormal, mode == 1 && uvIntensity == 170 ? HIGH : LOW); // LED para intensidad Normal
digitalWrite(ledHigh, mode == 1 && uvIntensity == 255 ? HIGH : LOW); // LED para intensidad Alta
}
al verificar el codigo me sale error
exit status 1
cannot bind non-const lvalue reference of type 'int&' to an rvalue of type 'int'
por favor su apoyo.