grazie a chi mi aiuterà
estrapolo solo il listato del timer, sicuramente non compilerà perchè ci sono variabili inerenti il listato completo
Codice: Seleziona tutto
#include <EEPROM.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 4);
#define Pause 61 //PULSANTE PAUSA TIMER
#define Reset 56 //PULSANTE RESET FORZATO TIMER
#define Start 60 //PULSANTE START TIMER
#define led 58 //LED RELE TIMER
#define buzzer 59 //SEGNALATORE ACUSTICO TIMER
#define encoderPinA 2 //ENCODER TIMER CW
#define encoderPinB 3 //ENCODER TIMER CCW
#define encoderButton 57 //PULSANTE ENCODER TIMER
byte pos, actPos;
int HMS = 0;
int hours = 0;
int minutes = 0;
int seconds = 0;
unsigned long time1 = 0;
bool mask = 0, toggle = 0;
int pause = 0;
int reset = 0;
int starting = 0;
int encoderPos = 0;
unsigned int lastReportedPos = 1;
static boolean rotating = false;
boolean A_set = false;
boolean B_set = false;
int contatoreFineTempo;
void setup() {
pinMode (Pause, INPUT_PULLUP);
pinMode (Reset, INPUT_PULLUP);
pinMode (Start, INPUT_PULLUP);
pinMode (led, OUTPUT);
pinMode (buzzer, OUTPUT);
pinMode (encoderPinA, INPUT_PULLUP);
pinMode (encoderPinB, INPUT_PULLUP);
pinMode (encoderButton, INPUT_PULLUP);
attachInterrupt (0, doEncoderA, CHANGE);
attachInterrupt (1, doEncoderB, CHANGE);
digitalWrite (led, LOW);
digitalWrite (buzzer, LOW);
lcd.init();
lcd.backlight();
lcd.clear();
lcd.print("IdeltaN");
lcd.setCursor(0, 1);
lcd.print("deltaT");
lcd.setCursor(15, 0);
lcd.print("A");
lcd.setCursor(15, 1);
lcd.print("S");
lcd.setCursor(9, 0);
lcd.print("0,000");
lcd.setCursor(10, 1);
lcd.print("0,00");
lcd.setCursor(-4,2);
lcd.print("Timer Count Down");
lcd.setCursor(0, 3);
lcd.print("00:00:00");
time1=millis();
}
void loop() {
if ((unsigned long) millis() - time1 > 1000 and mask == 1) {
lcd.setCursor(0, 3);
lcd.print(hours);
lcd.setCursor(2, 3);
lcd.print(':');
lcd.setCursor(3, 3);
lcd.print(minutes);
lcd.setCursor(5, 3);
lcd.print(':');
lcd.setCursor(6, 3);
lcd.print(seconds);
if(minutes == 0 and hours == 0 and seconds == 0) { //When Timer Finish
digitalWrite(led, LOW);
myDigitalWrite(ledPinOFF, HIGH);
myDigitalWrite(ledPinON, LOW);
while(mask = 1) {
contatoreFineTempo++;
Serial.print("contatore");
Serial.println(contatoreFineTempo);
lcd.setCursor(0, 3);
lcd.print("Finished");
digitalWrite (buzzer, HIGH);
delay(250);
lcd.setCursor(0, 3);
lcd.print(" ");
digitalWrite (buzzer, LOW);
delay(250);
if (contatoreFineTempo >= 5) {
contatoreFineTempo = 0;
if (contatoreFineTempo == 0) {
mask = 0;
break;
}
}
}
lcd.setCursor(0, 3);
lcd.print("00:00:00");
if (ledState16 == HIGH) {
hours = EEPROM.read(1);
minutes = EEPROM.read(2);
seconds = EEPROM.read(3);
}
} else
seconds --;
if (seconds < 0) {
seconds = 59;
minutes --;
}
if (minutes < 0) {
minutes = 59;
hours --;
}
time1 = millis();
}
if (digitalRead(encoderButton) == LOW and mask == 0) {
while (digitalRead(encoderButton) == LOW);
HMS = HMS + 1;
if (HMS == 4)
/*
if (HMS == 5)
*/
{
HMS = 1;
}
delay(100);
if (HMS == 1) {
lcd.setCursor(-4, 2);
lcd.print(" ");
lcd.setCursor(-1, 2);
lcd.print("Set hours");
}
else if (HMS == 2) {
lcd.setCursor(-4, 2);
lcd.print(" ");
lcd.setCursor(-1, 2);
lcd.print("Set minutes");
}
else if (HMS == 3) {
lcd.setCursor(-4, 2);
lcd.print(" ");
lcd.setCursor(-1, 2);
lcd.print("Set seconds");
}
/*
else if (HMS == 4) {
lcd.setCursor(-4, 2);
lcd.print(" ");
lcd.setCursor(-4, 2);
lcd.print("Timer Count Down");
}
*/
}
rotating = true; // reset the debouncer
encoderPos = constrain(encoderPos, -1, 1);
if (lastReportedPos != encoderPos) {
if (HMS == 1) {
if (encoderPos == 1)
hours++;
if (encoderPos == -1)
hours--;
if (hours > 59) hours = 0;
if (hours < 0) hours = 59;
lcd.setCursor(0, 3);
lcd.print(hours);
Serial.print ("hours");
Serial.println (hours);
} else if (HMS == 2) {
if (encoderPos == 1)
minutes++;
if (encoderPos == -1)
minutes--;
if (minutes > 59) minutes = 0;
if (minutes < 0) minutes = 59;
lcd.setCursor(3, 3);
lcd.print(minutes);
Serial.print ("minutes");
Serial.println (minutes);
} else if (HMS == 3) {
if (encoderPos == 1)
seconds++;
if (encoderPos == -1)
seconds--;
if (seconds > 59) seconds = 0;
if (seconds < 0) seconds = 59;
lcd.setCursor(6, 3);
lcd.print(seconds);
Serial.print ("seconds");
Serial.println (seconds);
}
lcd.setCursor(0, 3);
if (hours <= 9)
{
lcd.print("0");
}
lcd.print(hours);
lcd.print(":");
if (minutes <= 9)
{;
lcd.print("0");
}
lcd.print(minutes);
lcd.print(":");
if (seconds <= 9)
{
lcd.print("0");
}
lcd.print(seconds);
if (ledState16 == HIGH) {
EEPROM.update(1, hours);
EEPROM.update(2, minutes);
EEPROM.update(3, seconds);
}
encoderPos = 0;
lastReportedPos = encoderPos;
}
if(digitalRead(Start) == LOW) {
while (digitalRead(Start) == LOW);
if (minutes > 0 or hours > 0 or seconds > 0) {
lcd.setCursor(-4, 2);
lcd.print(" ");
lcd.setCursor(-4, 2);
lcd.print("Timer Count Down");
lcd.setCursor(0, 3);
lcd.print(" ");
delay(500);
lcd.setCursor(2, 3);
lcd.print("Start");
delay(1000);
HMS = 0;
starting = 1;
mask = 1;
Serial.print("start");
Serial.println(Start);
Serial.print("mask");
Serial.println(mask);
digitalWrite(led,HIGH);
if (starting == 1 and mask == 1) {
myDigitalWrite (ledPinON, HIGH);
myDigitalWrite (ledPinOFF, LOW);
eravamoAccesi = HIGH;
toggle = 0;
pos = 0;
}
if (starting == 0) {
myDigitalWrite (ledPinOFF, HIGH);
myDigitalWrite (ledPinON, LOW);
eravamoAccesi = LOW;
}
}
}
lcd.setCursor(0, 3);
if (hours <= 9)
{
lcd.print("0");
}
lcd.print(hours);
lcd.print(":");
if (minutes <= 9)
{
lcd.print("0");
}
lcd.print(minutes);
lcd.print(":");
if (seconds <= 9)
{
lcd.print("0");
}
lcd.print(seconds);
if (buttonStatus1 == HIGH or buttonStatus2 == HIGH) {
mask = 0;
}
if (buttonStatus3 == HIGH) {
if (minutes > 0 or hours > 0 or seconds > 0) {
mask = 1;
}
}
if (digitalRead(Pause) == LOW) {
delay(100);
if (minutes > 0 or hours > 0 or seconds > 0) {
if (digitalRead(ledPinON) == HIGH) {
pause = 1;
mask = 0;
if (mask == 0) {
myDigitalWrite (ledPinOFF, HIGH);
myDigitalWrite (ledPinON, LOW);
eravamoAccesi = LOW;
}
if (pause == 1) {
lcd.setCursor(0, 3);
lcd.print(" ");
delay(10);
lcd.setCursor(2, 3);
lcd.print("Pause");
delay(1000);
lcd.setCursor(0, 3);
lcd.print(hours);
lcd.setCursor(2, 3);
lcd.print(':');
lcd.setCursor(3, 3);
lcd.print(minutes);
lcd.setCursor(5, 3);
lcd.print(':');
lcd.setCursor(6, 3);
lcd.print(seconds);
pause = 0;
}
}
}
}
if (digitalRead(Reset) == LOW) {
delay(100);
reset = 1;
mask = 0;
digitalWrite(led, LOW);
if (reset == 1) {
myDigitalWrite (ledPinOFF, HIGH);
myDigitalWrite (ledPinON, LOW);
eravamoAccesi = LOW;
if (minutes > 0 or hours > 0 or seconds > 0) {
minutes = 0;
hours = 0;
seconds = 0;
lcd.setCursor(0, 3);
lcd.print(" ");
delay(10);
lcd.setCursor(2, 3);
lcd.print("Reset");
delay(1000);
lcd.setCursor(0, 3);
lcd.print("00:00:00");
reset = 0;
if (ledState16 == HIGH) {
hours = EEPROM.read(1);
minutes = EEPROM.read(2);
seconds = EEPROM.read(3);
}
}
}
}
}
}
void doEncoderA() {
if (rotating) delay(1);
if (digitalRead(encoderPinA) != A_set) {
A_set = !A_set;
if (A_set and !B_set)
encoderPos = -1;
rotating = false;
}
}
void doEncoderB() {
if (rotating) delay (1);
if (digitalRead(encoderPinB) != B_set) {
B_set = !B_set;
if (B_set and !A_set)
encoderPos = 1;
rotating = false;
}
}