Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Timer program v.0.9 beta, Author: Szerzetes, Licenc: free
- #include <Wire.h>
- #include <LiquidCrystal_I2C.h> // https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads
- #include <Timer.h>
- #include <EEPROM.h>
- Timer t;
- #define KeySetting 10
- #define KeyPlus 11
- #define KeyMinus 12
- #define Relay 9 // The number of outputs that the timer switches
- // addr, en,rw,rs,d4,d5,d6,d7,bl,blpol
- LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
- int Time,TimeKey;
- byte TimeLow,TimeHigh;
- void setup()
- {
- pinMode(KeySetting,INPUT);
- pinMode(KeyPlus,INPUT);
- pinMode(KeyMinus,INPUT);
- pinMode(Relay,OUTPUT);
- digitalWrite(KeySetting,HIGH);
- digitalWrite(KeyPlus,HIGH);
- digitalWrite(KeyMinus,HIGH);
- // *********************************** Write here what happens when the timer is switched on *********************************
- digitalWrite(Relay,HIGH);
- // *********************************** Relay output is set ***********************************
- lcd.begin(16,2);
- TimeLow=EEPROM.read(0);
- TimeHigh=EEPROM.read(1);
- if (TimeHigh==0 and TimeLow==0) TimeLow=1; // If EEPROM is empty, the time value will be 1 secundum
- Time=TimeHigh*256+TimeLow;
- int tickEvent = t.every(1000, tikkel, 100 );
- TimeKey=500;
- }
- void loop() {
- if (digitalRead(KeySetting)==1) {
- t.update();
- }
- else {
- lcd.clear();
- lcd.print("Time setting: ");
- TimeLow=EEPROM.read(0);
- TimeHigh=EEPROM.read(1);
- Time=TimeHigh*256+TimeLow;
- while (digitalRead(KeySetting)==0) {
- if (digitalRead(KeyPlus)==0 ) {
- Time++;
- if (Time>=600) Time=600;
- delay(TimeKey);
- if (TimeKey>=50) TimeKey-=30;
- goto PushEnd;
- } // endif
- if (digitalRead(KeyMinus)==0 ) {
- Time--;
- if (Time<=0) Time=1;
- delay(TimeKey);
- if (TimeKey>=50) TimeKey-=30;
- goto PushEnd;
- }
- TimeKey=500;
- PushEnd:
- lcd.setCursor(1,1);
- TimePrintLCD();
- }
- lcd.setCursor(10,1);
- lcd.print("Save");
- TimeHigh=Time/256;
- TimeLow=Time-256*TimeHigh;
- EEPROM.write(0,TimeLow);
- EEPROM.write(1,TimeHigh);
- delay(2000);
- lcd.clear();
- }
- }
- void tikkel() {
- if (Time==0) {
- lcd.setCursor(0,0);
- lcd.print("Time over. ");
- // ************************************ Write here what happens when the timer is switched off. ***************************************
- digitalWrite(Relay,LOW);
- // *********************************** Relay output is reset ***********************************
- }
- else {
- Time--;
- lcd.setCursor(0,0);
- lcd.print("Time: ");
- TimePrintLCD();
- }
- }
- void TimePrintLCD() {
- byte TMinute, TSecundum;
- String tmp;
- TMinute=Time/60;
- TSecundum=Time-TMinute*60;
- tmp=""; if (TMinute<=9) tmp= "0";
- lcd.print(tmp);
- lcd.print(TMinute);
- lcd.print(":");
- tmp=""; if (TSecundum<=9) tmp= "0";
- lcd.print(tmp);
- lcd.print(TSecundum);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement