Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //https://arduino-info.wikispaces.com/LCD-Blue-I2C
- #include <Wire.h>
- #include <LiquidCrystal_I2C.h>
- #include <Timer.h>
- #include <EEPROM.h>
- #include <Time.h>
- #include <DS1302.h>
- DS1302 rtc(10, 9, 8);
- Timer t;
- Time ti = rtc.time();
- byte Motorok[23]; //Motorok PWM értékei: Motor1 éjjeli, Motor2 éjjeli, Motor1 nappali, Motor2 nappali, Motor1 turbo, Motor2 turbo, turbo idő,
- String sz[24];
- int Turbo=0; //Turbo üzemmód be van-e kapcsolva
- String tmp="";
- byte Ido=0;
- byte TPerc=0;
- byte TSec=0;
- byte menu=0;
- byte menuval=0;
- byte lighttime=40;
- byte lightt=30;
- bool light=true;
- byte naptar[7];
- int kikapcs=65535;
- int kikapcs1=65535;
- #define GombSetting 7 //Beállítás mód
- #define GombEjjel A3
- #define GombNappal A2
- #define GombTurbo A1
- #define GombStop A0
- #define Relay1 4
- #define Relay2 3
- #define Motor1 5
- #define Motor2 6
- // Set the pins on the I2C chip used for LCD connections:
- // addr, en,rw,rs,d4,d5,d6,d7,bl,blpol
- LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Set the LCD I2C address
- void setup()
- {
- //rtc.writeProtect(false);
- //Time ti(2018, 4, 26, 21, 40, 50, Time::kThursday);
- //rtc.time(ti);
- tone(12,700,200);
- delay(200);
- tone(12,600,200);
- delay(200);
- tone(12,500,200);
- Serial.begin(115200);
- Serial.print("Setup ");
- pinMode(GombSetting, INPUT);
- pinMode(GombEjjel, INPUT);
- pinMode(GombNappal, INPUT);
- pinMode(GombTurbo, INPUT);
- pinMode(GombStop, INPUT);
- digitalWrite(GombSetting, HIGH);
- digitalWrite(GombEjjel, HIGH);
- digitalWrite(GombNappal, HIGH);
- digitalWrite(GombTurbo, HIGH);
- digitalWrite(GombStop, HIGH);
- pinMode(Motor1, OUTPUT);
- pinMode(Motor2, OUTPUT);
- pinMode(Relay1, OUTPUT);
- pinMode(Relay2, OUTPUT);
- digitalWrite(Relay1, LOW);
- digitalWrite(Relay2, LOW);
- lcd.begin(16,4); // lcd alaphelyzetbe állítás
- Serial.println("LCD start");
- lcd.clear();
- lcd.setCursor(0,0);
- lcd.print("OK");
- sz[0]="Ejjel Motor1";
- sz[1]="Ejjel Motor2";
- sz[2]="Nappal Motor1";
- sz[3]="Nappal Motor2";
- sz[4]="Turbo Motor1";
- sz[5]="Turbo Motor2";
- sz[6]="Turbo ido perc";
- sz[7]="Bekapcsolas Ora";
- sz[8]="Bekapcsolas Perc";
- sz[9]="Kikapcsolas Ora";
- sz[10]="Kikapcsolas Perc";
- sz[11]="Vasarnap";
- sz[12]="Hetfo";
- sz[13]="Kedd";
- sz[14]="Szerda";
- sz[15]="Csutortok";
- sz[16]="Pentek";
- sz[17]="Szombat";
- sz[18]="Ev (2000+)";
- sz[19]="Honap (1-12)";
- sz[20]="Nap (1-31!)";
- sz[21]="Ora (0-23)";
- sz[22]="Perc (0-59)";
- sz[23]="Nap neve (1-7)";
- sz[24]="Save";
- delay(500);
- // lcd.noBacklight();
- // delay(500);
- // lcd.backlight();
- Serial.println(".");
- int tickEvent = t.every(1000, tikkel, 2000 );
- Serial.print("1 second tikkelés id=");
- Serial.println(tickEvent);
- delay(500);
- //Motorok sebesség és turbo idő beolvasása
- for (int i=0; i <= 17; i++){
- Motorok[i]=EEPROM.read(i);
- }
- Motorok[18]=ti.yr-2000;
- Motorok[19]=ti.mon;
- Motorok[20]=ti.date;
- Motorok[21]=ti.hr;
- Motorok[22]=ti.min;
- Motorok[23]=ti.day;
- naptartxt();
- Ido=Motorok[6];
- lcd.backlight();
- for (int i=9; i = 0; i--){
- lcd.setCursor(i,0);
- lcd.print("Hello! ");
- delay(100);
- }
- ejjelitxt(); //Reset utáni kezdő lépernyő
- }
- void loop() {
- t.update(); //Timer frissítés
- if (digitalRead(GombSetting)==1) {
- //Normál ág
- if (digitalRead(GombEjjel)==0 and light==true) {
- lighttime=lightt;
- Serial.println ("Ejjel");
- ejjelitxt();
- tone(12,700,200);
- delay(500);
- }
- if (digitalRead(GombEjjel)==0) {
- lighttime=lightt;
- lcd.backlight();
- light=true;
- delay(1000);
- }
- if (digitalRead(GombNappal)==0 and light==true) {
- lighttime=lightt;
- Serial.println ("Nappal");
- nappalitxt();
- tone(12,700,200);
- delay(500);
- }
- if (digitalRead(GombNappal)==0) {
- lighttime=lightt;
- lcd.backlight();
- light=true;
- delay(1000);
- }
- if (digitalRead(GombStop)==0 and light==true) {
- lighttime=lightt;
- Serial.println ("Stop");
- stoptxt();
- tone(12,700,200);
- delay(500);
- }
- if (digitalRead(GombStop)==0) {
- lighttime=lightt;
- lcd.backlight();
- light=true;
- delay(1000);
- }
- if (digitalRead(GombTurbo)==0 and Turbo==0 and light==true) {
- lighttime=lightt;
- Serial.println (Motorok[6]);
- Serial.println ("Turbo");
- Turbo=1;
- //Perc=Motorok[6];
- TPerc=Ido;
- TSec=0;
- digitalWrite(Relay1,HIGH);
- digitalWrite(Relay2,HIGH);
- analogWrite(Motor1,Motorok[4]);
- analogWrite(Motor2,Motorok[5]);
- turbotxt();
- tone(12,700,200);
- delay(100);
- }
- if (digitalRead(GombTurbo)==0) {
- lighttime=lightt;
- lcd.backlight();
- light=true;
- delay(1000);
- }
- }
- else {
- //Beállítás ág
- lcd.backlight();
- Serial.println ("Beállitas");
- analogWrite(Motor1,0);
- analogWrite(Motor2,1);
- digitalWrite(Relay1, LOW);
- digitalWrite(Relay2, LOW);
- delay(100);
- beallittxt();
- delay(1000);
- beallitsz();
- while (digitalRead(GombSetting)==0) {
- if (digitalRead(GombStop)==0 ) {
- Serial.println ("Stop gomb beallitas");
- menu -= 1;
- if (menu==255) {
- menu=0;
- }
- beallitsz();
- tone(12,700,200);
- delay(500);
- }
- if (digitalRead(GombTurbo)==0 ) {
- Serial.println ("Turbo gomb beallitas");
- menu += 1;
- if (menu==24) {
- menu=23;
- }
- beallitsz();
- tone(12,700,200);
- delay(500);
- }
- if (digitalRead(GombEjjel)==0 ) {
- Serial.println ("Ejjel gomb beallitas");
- Motorok[menu] += 1;
- beallitsz();
- tone(12,700,200);
- delay(200);
- }
- if (digitalRead(GombNappal)==0 ) {
- Serial.println ("Nappal gomb beallitas");
- menuval=Motorok[menu];
- Motorok[menu] -= 1;
- if (Motorok[menu]==255 and menu>=6 ) {
- Motorok[menu]=0;
- }
- beallitsz();
- tone(12,700,200);
- delay(200);
- }
- }
- Serial.print("Save");
- for (int i=0; i <= 17; i++){
- EEPROM.write(i,Motorok[i]);
- }
- Ido=Motorok[6]; //Turbo idő
- rtc.writeProtect(false);
- rtc.halt(false);
- ti.yr=Motorok[18]+2000;
- ti.mon=Motorok[19];
- ti.date=Motorok[20];
- ti.hr=Motorok[21];
- ti.min=Motorok[22];
- ti.day=Motorok[23];
- rtc.time(ti);
- rtc.writeProtect(true);
- lcd.clear();
- lcd.setCursor(4,0);
- lcd.print("Valassz");
- lcd.setCursor(2,1);
- lcd.print("uzemmodot");
- }
- }
- void beallitsz(void) {
- lcd.clear();
- lcd.setCursor(0,0);
- lcd.print(sz[menu]);
- lcd.setCursor(14,3);
- lcd.print(menu);
- lcd.setCursor(6,1);
- lcd.print(Motorok[menu]);
- delay(100);
- }
- void beallittxt(void) {
- Turbo=0;
- digitalWrite(Relay1,LOW);
- digitalWrite(Relay2,LOW);
- lcd.clear();
- lcd.setCursor(0,0);
- lcd.print("Beallitas");
- }
- void ejjelitxt(void) {
- Turbo=0;
- digitalWrite(Relay1,HIGH);
- digitalWrite(Relay2,HIGH);
- analogWrite(Motor1,Motorok[0]);
- analogWrite(Motor2,Motorok[1]);
- lcd.clear();
- lcd.setCursor(1,0);
- lcd.print("Ejjeli uzemmod");
- }
- void nappalitxt(void) {
- Turbo=0;
- digitalWrite(Relay1,HIGH);
- digitalWrite(Relay2,HIGH);
- analogWrite(Motor1,Motorok[2]);
- analogWrite(Motor2,Motorok[3]);
- lcd.clear();
- lcd.setCursor(1,0);
- lcd.print("Nappali uzemmod");
- }
- void stoptxt(void) {
- Turbo=0;
- digitalWrite(Relay1,LOW);
- digitalWrite(Relay2,LOW);
- analogWrite(Motor1,0);
- analogWrite(Motor2,0);
- lcd.clear();
- lcd.setCursor(6,0);
- lcd.print("STOP");
- }
- void turbotxt(void) {
- lcd.clear();
- lcd.setCursor(5,0);
- lcd.print("TURBO");
- lcd.setCursor(0,1);
- tmp="";
- if (TPerc<=9){
- tmp="0";
- }
- lcd.setCursor(5,1);
- lcd.print(tmp);
- lcd.print(TPerc);
- lcd.print(":");
- tmp="";
- if (TSec<=9){
- tmp="0";
- }
- lcd.print(tmp);
- lcd.print(TSec);
- }
- void naptartxt() {
- Time ti=rtc.time();
- naptar[0]=ti.yr-2000;
- naptar[1]=ti.mon;
- naptar[2]=ti.date;
- naptar[3]=ti.hr;
- naptar[4]=ti.min;
- naptar[5]=ti.sec;
- naptar[6]=ti.day;
- lcd.setCursor(3,3);
- lcd.print(ti.yr);
- lcd.print("-");
- tmp=""; if (ti.mon<=9) { tmp="0"; }
- lcd.print(tmp);
- lcd.print(ti.mon);
- lcd.print("-");
- tmp=""; if (ti.date<=9) { tmp="0"; }
- lcd.print(tmp);
- lcd.print(ti.date);
- lcd.print(" ");
- lcd.setCursor(3,2);
- tmp=""; if (ti.hr<=9) { tmp="0"; }
- lcd.print(tmp);
- lcd.print(ti.hr);
- lcd.print(":");
- tmp=""; if (ti.min<=9) { tmp="0"; }
- lcd.print(tmp);
- lcd.print(ti.min);
- lcd.print(":");
- tmp=""; if (ti.sec<=9) { tmp="0"; }
- lcd.print(tmp);
- lcd.print(ti.sec);
- lcd.print(" ");
- lcd.setCursor(3,1);
- lcd.print(sz[11+ti.day]);
- lcd.print(" ");
- lcd.setCursor(14,1);
- lcd.print(Motorok[11+naptar[6]]);
- //lcd.print(ti.sec);
- //lcd.print(" ");
- //lcd.print(":");
- //lcd.print(ti.sec);
- }
- void tikkel() {
- naptartxt();
- lighttime -= 1;
- if (lighttime == 0) {
- lcd.noBacklight();
- lighttime=lightt;
- light=false;
- }
- //Serial.println(millis() );
- if (Turbo==1) {
- if (TSec!=0) {
- TSec --;
- }
- Serial.print(TPerc);
- Serial.print(":");
- Serial.println(TSec);
- turbotxt();
- if (TPerc==0 and TSec==0) {
- Serial.println("Turbo vége");
- Turbo=0;
- delay(1000);
- nappalitxt();
- }
- if (TSec==0) {
- TSec=60;
- TPerc --;
- }
- }
- Serial.print("naptar: ");
- Serial.print(naptar[6]);
- Serial.print(" bool: ");
- Serial.println(Motorok[10+naptar[6]]); //naptar(6)-ban a napok száma, 0 - nincs, hiba, 1 - vasárnap, 2 - hétfő ...
- if (Motorok[10+naptar[6]] == 1) { //Motorok (10)-től, hogy azon a napon kell-e
- /*
- Serial.print(Motorok[7]);
- Serial.print(" ");
- Serial.print(Motorok[8]);
- Serial.print(" ");
- Serial.print(Motorok[9]);
- Serial.print(" ");
- Serial.print(Motorok[10]);
- Serial.print(" --- ");
- Serial.print(naptar[3]);
- Serial.print(" nap ");
- Serial.println(naptar[4]);
- */
- if (Motorok[7]==naptar[3] and Motorok[8]==naptar[4] and naptar[5]==0) {
- Serial.println("BE nappali automata");
- nappalitxt();
- }
- if (Motorok[9]==naptar[3] and Motorok[10]==naptar[4] and naptar[5]==0) {
- ejjelitxt();
- Serial.println("KI nappali automata");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement