Szerelo

9 channel Timer with 5 languages voice+alarm sound and 2 p. 10 buttons 433 MHz remote control

Jul 10th, 2021 (edited)
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 30.62 KB | None | 0 0
  1. //  2021.07.10. v.1.0
  2. // Gépekhez időzítő, 9 csatorna
  3. // 2*16-os LCD kijelzővel
  4. // 7 szegmenses kijelző, nano, encoder
  5. // 1 másodperces tikkeléssel, óra, perc, másodperc beállítási lehetőséggel, érték mentve.
  6. // Alap helyzetben csak a kijelzőn látszik az utoljára megnézett vagy beállított hátralévő idő
  7. // Encoder állításával a timerek között lehet lépkedni, melynek van Active és nem aktív állása
  8. // 2 gomb van.
  9. // 1. Encoder gombja, Start - a kijelzőn aktuálisan látható timer indul
  10. // 2. Reset - A riasztás törlése
  11. // A nagy, 1 digites kijelzőn az éppen aktuális timer száma jelenik meg, kivéve, ha riasztás van.
  12. // Ha 10 sec-ig nincs változás, akkor automatikusan eltűnik. dispOff=10
  13. // Riasztás esetén a lejárt időzítő száma látható, valamint hangjelzés is hallható, mindig az utolsónak a szignálja.
  14. // A risztást nyugtázni kell, addig lesz, amíg nincs megnyova a reset gomb.
  15. // Ha valamilyen beállításban lesz riasztás, akkor NEM menti az aktuális értéket és kilép a beállításból. A beállításba újból be kell lépni, nem lép vissza automatikusan a riasztás után.
  16. // Kezel 2 db 10 gombos távirányítót. A gombok 1-9-ig a timerek indítására szolgálnak, míg a 10. gomb riasztás esetén törli az aktuális riasztást.
  17.  
  18. // EEPROM memory map
  19. // 02-20 Timers starting time
  20. // 22 - Volume
  21. // 23 - Brightness
  22. // 24 - Language (1-English, 2-Deutsch, - 3-France, 4-Spain, 5-Hungary)
  23. // 25 - Maximum number of alarm MP3s (in folder 99)
  24. // 31-39 - Number of MP3 files assigned to the timers (in folder 99)
  25. // 40-120 - Remote control data
  26. // 130-150 - Number of timer alarms, not yet included!
  27.  
  28. #include <EEPROM.h>
  29. #include <LiquidCrystal_I2C.h>
  30. #include <Rotary.h>
  31. #include "SoftwareSerial.h"
  32. #include "DFRobotDFPlayerMini.h"
  33. #include "customchar.h"
  34. #include <RCSwitch.h>
  35.  
  36. // TPIC6C596 shift register
  37. #define DOUT 4
  38. #define CLK  6
  39. #define NLE 7
  40. #define BR  5
  41.  
  42. #define encButton   A0
  43. #define Button  A3
  44.  
  45. #define CHKDISP  3
  46.  
  47. unsigned long lastDebounceTime = 0,lastDebounceTime1 = 0;
  48. unsigned long debounceDelay = 50;
  49. unsigned long longPressDelay = 1000;
  50. unsigned long buttonCounter,buttonCounter1;
  51. unsigned long currentMillis;
  52. unsigned long previousMillis;
  53. bool readingButton,readingButton1;
  54. bool buttonShort=false,buttonShort1=false;
  55. bool buttonLong=false,buttonLong1=false;
  56. bool buttonShortPress=false,buttonShortPress1=false;
  57. bool buttonLongPress=false,buttonLongPress1=false;
  58. bool reading,reading1;
  59.  
  60. unsigned long  remoteData[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20};     // Remote control codes, 2 * 10 buttons
  61.  
  62. unsigned long val=0;
  63. //             0   1   2   3   4   5   6   7   8   9  _  -   H   E   L
  64. const byte kari[] ={123, 65,179,227,201,234,250, 67,251,235,0,128,217,186, 56};
  65. unsigned int  timerKezd[]={100,600,600,600,600,600,600,600,600,600};   // Initial value of timers
  66. unsigned int  timer[] =   { 0,   0,  0,  0,  0,  0,  0,  0,  0,  0};     // The current value of the timers
  67. byte  timerMP3[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};     // The serial number of the MP3 for the timers
  68. bool riaszt[] = {0,0,0,0,0,0,0,0,0,0};     // Do the timers alarm
  69. bool voice=true;  // In the event of an alarm, speak or music, speak first
  70. byte timerNum=1;   // The number of the current timer
  71. byte alarmNum=0;   // The number of the current alarm, which timer is alarming, 0 - none
  72. byte ora, perc, sec;
  73. byte dispOff=10;    // Turn off the large display
  74.  
  75. //                   0   1   2   3   4   5   6   7   8   9  10 11
  76. const byte brightness[]={255,249,240,229,217,204,189,170,148,119,79,10};
  77. byte actualBrightness;
  78. byte actualVolume;
  79. byte maxMP3=38;   // the MP3s are in folder 99.
  80. byte actualMP3=0, counterMP3=0;
  81. byte type;
  82. bool setting=false;
  83. bool settingVolume=false;
  84. bool settingBrightness=false;
  85. bool setActual=false;   // Set the current time
  86. bool setVol=false;    // When setting the timer time, add the MP3 associated with the current timer
  87. //unsigned int counter=0;
  88. byte counter=0;
  89. byte lang=0;       // A nyelv száma (1-5)
  90. float tmp=0;
  91. long value;   // RCSwitch
  92. unsigned char result;
  93.  
  94. LiquidCrystal_I2C lcd(0x27,16,2);  // set the LCD address to 0x27 for a 16 chars and 2 line display
  95.  
  96. Rotary r = Rotary(A2, A1);            // define rottary encoder and pins
  97. SoftwareSerial mySoftwareSerial(9, 8); // RX, TX
  98. RCSwitch mySwitch = RCSwitch();
  99. DFRobotDFPlayerMini myDFPlayer;
  100.  
  101. void setup() {
  102.   lcd.init();                      // initialize the lcd
  103.   lcd.backlight();
  104.  
  105.   r.begin(true);
  106.  
  107.   pinMode(DOUT, OUTPUT);
  108.   pinMode(CLK, OUTPUT);
  109.   pinMode(NLE, OUTPUT);
  110.   pinMode(encButton, INPUT_PULLUP);
  111.   pinMode(Button, INPUT_PULLUP);
  112.   pinMode(CHKDISP, INPUT_PULLUP);
  113.   digitalWrite(NLE, HIGH);
  114.   digitalWrite(CLK, LOW);
  115.   digitalWrite(DOUT, LOW);
  116.   analogWrite(BR, 220);
  117.   mySoftwareSerial.begin(9600);
  118.   mySwitch.enableReceive(0);  // Receiver on interrupt 0 => that is pin #2
  119.   Serial.begin(115200);
  120.   Serial.println("Start ...");
  121.   for (byte j=6;j>0;j--){
  122.     for (byte i=0;i<8;i++){
  123.       s0[i]=32-pow(2,j-1);
  124.     }
  125.   lcd.createChar(6-j, s0);
  126.   }
  127.   shift(0);   //clear
  128.   lcd.clear();
  129.  
  130.   if (!myDFPlayer.begin(mySoftwareSerial)) {  //Use softwareSerial to communicate with mp3.
  131.     lcd.print(" Please insert");
  132.     lcd.setCursor(0,1);
  133.     lcd.print("  the SD card!");
  134.     //while(true);
  135.     delay(5000);
  136.     lcd.clear();
  137.   }
  138.   if (digitalRead(CHKDISP)==HIGH) {  //
  139.     lcd.print("No 7 seq. displ.");
  140.     lcd.setCursor(0,1);
  141.     lcd.print("  Need connect");
  142.     //while(true);
  143.     delay(5000);
  144.     lcd.clear();
  145.   }
  146.   //ment();   // Set the first time
  147.   for (byte i=1;i<10;i++){
  148.     EEPROM.get(i*2, timerKezd[i]);
  149.     timerMP3[i]=EEPROM.read(i+30);
  150.   }
  151.   for (byte i=0;i<20;i++){
  152.     EEPROM.get(40+i*4, remoteData[i]);
  153.     Serial.print(i);
  154.     Serial.print(" ");
  155.     Serial.print(40+i*4);
  156.     Serial.print(" ");
  157.     Serial.println(remoteData[i]);
  158.   }
  159. //  EEPROM.write(22,10);    // Set the first time
  160. //  EEPROM.write(23,3);
  161.   actualVolume=EEPROM.read(22);
  162.   actualBrightness=EEPROM.read(23);
  163.   lang=EEPROM.read(24);
  164.   maxMP3=EEPROM.read(25);
  165.   if (lang==255) lang=1;   // If the value is too large (empty EEPROM), it will be the default value, English
  166.   myDFPlayer.volume(actualVolume);  //Set volume value. From 0 to 30
  167.   myDFPlayer.playFolder(lang, 1);  // Welcome voice
  168.   analogWrite(BR, brightness[actualBrightness]);
  169.   lcd.setCursor(0,0);
  170.   langWorld(1);
  171.   lcd.print(actualBrightness);
  172.   lcd.setCursor(0,1);
  173.   langWorld(2);
  174.   lcd.print(actualVolume);
  175.   delay(1000);
  176.   lcd.clear();
  177.   lcd.setCursor(2,0);
  178.   langWorld(3);
  179.   lcd.print(lang);
  180.   lcd.setCursor(2,1);
  181.   lcd.print(" MP3: ");
  182.   lcd.print(maxMP3);
  183.   delay(1000);
  184.   counter=0;
  185.   if (digitalRead(encButton)==LOW) counter++;
  186.   if (digitalRead(Button)==LOW) counter=counter+2;
  187.   Serial.println("Counter: ");
  188.   Serial.println(counter);
  189.  
  190.   if (counter==3) {
  191.     Serial.println("Remote SET");
  192.     kiir3();
  193.     while(!digitalRead(Button));
  194.     Serial.println("Remote SET start");
  195.     remoteSet();
  196.     counter=0;
  197.   }
  198.   if (counter==2) {
  199.     Serial.println("Lang SET");
  200.     lcd.clear();
  201.     lcd.setCursor(2,0);
  202.     langWorld(3);
  203.     lcd.print(lang);
  204.     lcd.setCursor(2,1);
  205.     langWorld(4);
  206.     while(!digitalRead(Button));
  207.     Serial.println("Lang SET start");
  208.     langSet();
  209.     EEPROM.write(24,lang);
  210.     counter=0;
  211.   }
  212.   if (counter==1) {
  213.     Serial.println("Alarm MP3 numset");
  214.     lcd.clear();
  215.     lcd.setCursor(0,0);
  216.     lcd.print("Maximum number");
  217.     lcd.setCursor(0,1);
  218.     lcd.print("of MP3s: ");
  219.     lcd.setCursor(10,1);
  220.     lcd.print(maxMP3);
  221.     while(!digitalRead(encButton));
  222.     Serial.println("Alarm MP3 numset start");
  223.     MP3Set();
  224.     if (maxMP3==0){
  225.       statRead();
  226.     } else {
  227.       EEPROM.write(25,maxMP3);
  228.     }
  229.     delay(2000);
  230.   }
  231.   lcd.clear();
  232.   kiir();
  233. }
  234.  
  235. void statRead(){
  236.   unsigned int count;
  237.   lcd.clear();
  238.   lcd.setCursor(0,0);
  239.   lcd.print("Statistics");
  240.   delay(1000);
  241.   //while(!digitalRead(Button));    // waiting for up button
  242.   counter=0;
  243.   while(digitalRead(encButton)){
  244.     result = r.process();
  245.     if (result==DIR_CCW and counter<10) {
  246.       counter++;
  247.       lcd.setCursor(10,1);
  248.       lcd.print(counter);
  249.       lcd.print("  ");
  250.       Serial.print(counter);
  251.       Serial.print(" ");
  252.       Serial.println(128+counter*2);
  253.     }
  254.     if (result==DIR_CW and counter>1) {
  255.       counter--;
  256.       lcd.setCursor(10,1);
  257.       lcd.print(counter);
  258.       lcd.print("  ");
  259.       Serial.print(counter);
  260.       Serial.print(" ");
  261.       Serial.println(128+counter*2);
  262.     }
  263.   }
  264. }
  265.  
  266.  
  267. void MP3Set(){
  268.   delay(1000);
  269.   while(!digitalRead(Button));    // waiting for up button
  270.   counter=0;
  271.   while(digitalRead(encButton)){
  272.     result = r.process();
  273.     if (result==DIR_CCW and maxMP3<250) {
  274.       maxMP3++;
  275.       lcd.setCursor(10,1);
  276.       lcd.print(maxMP3);
  277.       lcd.print("  ");
  278.     }
  279.     if (result==DIR_CW and maxMP3>1) {
  280.       maxMP3--;
  281.       lcd.setCursor(10,1);
  282.       lcd.print(maxMP3);
  283.       lcd.print("  ");
  284.     }
  285.   }
  286. }
  287.  
  288. void loop() {
  289.   currentMillis = millis();
  290.   if (currentMillis - previousMillis >= 1000) {   // Timer every 1 second due to display refresh
  291.     previousMillis = currentMillis;
  292.     tick();
  293.   }
  294.   pressButton();
  295.   pressButton1();
  296.  
  297.   result = r.process();
  298.   if (settingVolume==false) {   // Secondary adjustment function, volume and brightness adjustment
  299.     if (setting==false) {   // normal mode
  300.       if (buttonLong==true){    // Long press on the encoder button, enter the time setting menu
  301.         reading=false;
  302.         buttonLong=false;
  303.         Serial.println("Long Press Normal");   // The button has been pressed long time
  304.         if (riaszt[timerNum]==0) setting=true;    // Switches to setting only when there is no alarm
  305.         setActual=false;
  306.       }
  307.       if (buttonShort==true and readingButton==HIGH){   // Short press of encoder button, current timer START
  308.         reading=false;
  309.         buttonShort=false;
  310.         Serial.println("Short Press Normal");    // The button has been pressed short time  
  311.         if (alarmNum == 0) {
  312.           shift(kari[timerNum]);
  313.           dispOff=10;
  314.           timer[timerNum]=timerKezd[timerNum];
  315.           myDFPlayer.playFolder(lang, 1+timerNum);
  316.         }
  317.       }
  318.  
  319.       if (buttonLong1==true){   // long press reset button
  320.         reading1=false;
  321.         buttonLong1=false;
  322.         Serial.println("Long Press 1 Normal");   // The button has been pressed long time
  323.         settingVolume=true;
  324.         settingBrightness=false;    // It starts with a volume setting
  325.         myDFPlayer.playFolder(99, 11);    // The number of the randomly selected audio file for the volume setting is 11
  326.         kiir1();
  327.       }
  328.       if (buttonShort1==true and readingButton1==HIGH){     // short press reset button, clear alarm
  329.         reading1=false;
  330.         buttonShort1=false;
  331.         Serial.println("Short Press 1 Normal");    // The button has been pressed short time    
  332.         riaszt[alarmNum]=false;
  333.         voice=true;
  334.         myDFPlayer.pause();  //Stop the mp3
  335.         alarmNum=0;
  336.         dispOff=5;
  337.       }
  338.      
  339.       if (result == DIR_CCW and alarmNum==0) {    // If there is no active alarm, you can switch between timers
  340.         timerNum++;
  341.         if (timerNum==10) timerNum=9;
  342.         if (timer[timerNum]!=0) {
  343.           shift(kari[timerNum]);
  344.           dispOff=5;
  345.         } else {
  346.           shift(0);
  347.         }
  348.         kiir();
  349.       }
  350.       if (result == DIR_CW and alarmNum==0) {    // If there is no active alarm, you can switch between timers
  351.         timerNum--;
  352.         if (timerNum==0) timerNum=1;
  353.         if (timer[timerNum]!=0) {
  354.           shift(kari[timerNum]);
  355.           dispOff=5;
  356.         } else {
  357.           shift(0);
  358.         }
  359.         kiir();
  360.       }
  361.     } else {    // setting=true
  362.       if (buttonLong==true){
  363.         reading=false;
  364.         buttonLong=false;
  365.         Serial.println("Long Press Setting");   // The button has been pressed long time
  366.         setting=false;
  367.         ment();
  368.       }
  369.       if (buttonShort==true and readingButton==HIGH){
  370.         reading=false;
  371.         buttonShort=false;
  372.         Serial.println("Short Press Setting");    // The button has been pressed short time    
  373.         if (timer[timerNum]!=0) {    // The current timer can only be set to active if it is not zero
  374.           if (setActual==false) {
  375.             setActual=true;
  376.             kiir();
  377.           } else {
  378.             setActual=false;
  379.             kiir();
  380.           }
  381.         }
  382.       }
  383.       if (buttonLong1==true){   // long press reset button, exit the setting
  384.         reading1=false;
  385.         buttonLong1=false;
  386.         Serial.println("Long Press 1 Setting");   // The button has been pressed long time
  387.         if (setVol==false){   // Switch between timer time and associated MP3 setting
  388.           setVol=true;
  389.           actualMP3=timerMP3[timerNum];   // The MP3 number of the current timer
  390.           counterMP3=actualMP3;
  391.           kiir2();
  392.         } else {
  393.           setVol=false;
  394.           myDFPlayer.pause();  // Stop mp3
  395.           kiir();
  396.         }
  397.       }
  398.       if (buttonShort1==true and readingButton1==HIGH){     // reset button short press, MP3 setting
  399.         reading1=false;
  400.         buttonShort1=false;
  401.         Serial.println("Short Press 1 Setting");    // The button has been pressed short time    
  402.         actualMP3=counterMP3;
  403.         timerMP3[timerNum]=counterMP3;   // Enter the current timer MP3
  404.         kiir2();
  405.       }
  406.       if (result == DIR_CCW and setVol==false) {    // timer time setting if the MP3 track number setting is not
  407.         if (setActual==false) {
  408.           timerKezd[timerNum]+=60;
  409.           if (timerKezd[timerNum]>65000) timerKezd[timerNum]=65000;
  410.           kiir();
  411.         } else {
  412.           timer[timerNum]+=60;
  413.           if (timer[timerNum]>65000) timer[timerNum]=65000;
  414.           kiir();
  415.         }
  416.       }
  417.       if (result == DIR_CW and setVol==false) {    // timer time setting if the MP3 track number setting is not
  418.         if (setActual==false) {
  419.           timerKezd[timerNum]-=60;
  420.           if (timerKezd[timerNum]>65000 or timerKezd[timerNum]<60) timerKezd[timerNum]=60;
  421.           kiir();
  422.         } else {
  423.           timer[timerNum]-=60;
  424.           if (timer[timerNum]>65000 or timer[timerNum]<60) timer[timerNum]=60;
  425.           kiir();
  426.         }
  427.       } // end DIR_CW
  428.       if (result == DIR_CCW and setVol==true and counterMP3<maxMP3) {  // Set the MP3 sequence number if the counter is less than the max.
  429.         counterMP3++;
  430.         myDFPlayer.playFolder(99, counterMP3);
  431.         delay(200);
  432.         kiir2();
  433.       }
  434.       if (result == DIR_CW and setVol==true and counterMP3>0) {  // Set the MP3 track number if greater than 0
  435.         counterMP3--;
  436.         myDFPlayer.playFolder(99, counterMP3);
  437.         delay(200);
  438.         kiir2();
  439.       } // end DIR_CW
  440.     }     // END setting
  441.   } else {    // Setting volume or Brigthness, settingVolume=true
  442.     if (buttonLong1==true){   // long press reset button, exit the setting
  443.       reading1=false;
  444.       buttonLong1=false;
  445.       Serial.println("Long Press 1 Volume/Brightness setting");   // The button has been pressed long time
  446.       settingVolume=false;
  447.       myDFPlayer.pause();  // Stop mp3
  448.       shift(0);
  449.       kiir();
  450.       EEPROM.write(22,actualVolume);
  451.       EEPROM.write(23,actualBrightness);
  452.     }
  453.     if (buttonShort1==true and readingButton1==HIGH){     // reset button short press, switch between settings: volume / brightness
  454.       reading1=false;
  455.       buttonShort1=false;
  456.       Serial.println("Short Press 1 Volume/Brightness setting");    // The button has been pressed short time    
  457.       if (settingBrightness==false) {
  458.         settingBrightness=true;
  459.         myDFPlayer.pause();  // Stop mp3
  460.         shift(kari[8]);
  461.         kiir1();
  462.       } else {
  463.         settingBrightness=false;
  464.         //myDFPlayer.play(11);  // Test mp3
  465.         myDFPlayer.playFolder(99, 11);
  466.         shift(0);
  467.         kiir1();
  468.       }
  469.     }
  470.     if (settingBrightness==false) {   // Volume setting
  471.       if (result == DIR_CCW and alarmNum==0) {    // If there is no active alarm, the value can be changed
  472.         actualVolume++;
  473.         if (actualVolume==31) actualVolume=30;
  474.         myDFPlayer.volume(actualVolume);  //Set volume value. From 0 to 30
  475.         kiir1();
  476.       }
  477.       if (result == DIR_CW and alarmNum==0) {    // If there is no active alarm, the value can be changed
  478.         actualVolume--;
  479.         if (actualVolume==0) actualVolume=1;
  480.         myDFPlayer.volume(actualVolume);  //Set volume value. From 0 to 30
  481.         kiir1();
  482.       }
  483.     } else {  // Brightness setting
  484.       if (result == DIR_CCW and alarmNum==0) {    // If there is no active alarm, the value can be changed
  485.         actualBrightness++;
  486.         if (actualBrightness==11) actualBrightness=10;
  487.         analogWrite(BR, brightness[actualBrightness]);
  488.         kiir1();
  489.       }
  490.       if (result == DIR_CW and alarmNum==0) {    // If there is no active alarm, the value can be changed
  491.         actualBrightness--;
  492.         if (actualBrightness==0) actualBrightness=1;
  493.         analogWrite(BR, brightness[actualBrightness]);
  494.         kiir1();
  495.       }
  496.     }
  497.   }
  498.   value=0;
  499.   chkRemote();
  500.   if (value!=0){
  501.     counter=99;
  502.     for (byte i=0;i<20;i++){
  503.       if (value==remoteData[i]) {
  504.         counter=i;
  505.       }
  506.     }
  507.     if (counter==9 or counter==19) {    // Unless button 10 on any remote control
  508.         riaszt[alarmNum]=false;
  509.         voice=true;
  510.         myDFPlayer.pause();  //Stop the mp3
  511.         alarmNum=0;
  512.         dispOff=5;
  513.     } else {
  514.       if (counter!=99) {    // Press 1-9 on the remote control
  515.         if (alarmNum==0) {    // No alarm, timer can be started
  516.           timerNum=(counter-(counter/10)*10+1);
  517.           shift(kari[timerNum]);
  518.           dispOff=10;
  519.           timer[timerNum]=timerKezd[timerNum];
  520.           myDFPlayer.playFolder(lang, 1+timerNum);
  521.         }
  522.       }
  523.     }
  524.   }
  525.   chkMP3();
  526. }  // END LOOP
  527.  
  528.  
  529. void chkMP3(){
  530.   if (myDFPlayer.available()) {   // Query MP3 player
  531.     type=myDFPlayer.readType();
  532.     Serial.print(type);
  533.     Serial.print(" DFPlayer ");
  534.     Serial.println(myDFPlayer.read());
  535.     if (type==6) {   // There is no such number of MP3s
  536.       Serial.println("There is no such number of MP3s");
  537.     }
  538.     if (alarmNum!=0){
  539.       if (voice==false) {   // speech or music test
  540.         myDFPlayer.playFolder(lang, 10+alarmNum);
  541.         voice=true;
  542.       } else {
  543.         myDFPlayer.playFolder(99, timerMP3[alarmNum]);
  544.         voice=false;
  545.       }
  546.     }
  547.   }
  548. }
  549.  
  550. void kiir1() {    // for secondary setting
  551.   lcd.clear();
  552.   if (settingBrightness==false) {
  553.     lcd.setCursor(0,0);
  554.     langWorld(2);   // Volume
  555.     lcd.print(actualVolume);
  556.     lcd.setCursor(0,1);
  557.     tmp=actualVolume;
  558.     tmp=tmp*2.67;
  559.     byte a1=tmp/5;
  560.     byte a2=tmp-a1*5;
  561.     for (byte i=0;i<a1;i++){
  562.       lcd.write(5);
  563.     }
  564.     lcd.write(a2);
  565.   } else {
  566.     lcd.setCursor(0,0);
  567.     langWorld(1);   // Brightness
  568.     lcd.print(actualBrightness);
  569.     lcd.setCursor(0,1);
  570.     tmp=actualBrightness;
  571.     tmp=tmp*8;
  572.     byte a1=tmp/5;
  573.     byte a2=tmp-a1*5;
  574.     for (byte i=0;i<a1;i++){
  575.       lcd.write(5);
  576.     }
  577.     lcd.write(a2);
  578.   }
  579. }
  580.  
  581. void kiir2() {
  582.   lcd.clear();
  583.   lcd.setCursor(0,0);
  584.   lcd.print("Timer: ");
  585.   lcd.print(timerNum);
  586.   lcd.setCursor(10,0);
  587.   if (counterMP3<10) lcd.print(" ");
  588.   lcd.print(counterMP3);
  589.   lcd.setCursor(0,1);
  590.   lcd.print("Actual MP3: ");
  591.   if (actualMP3<10) lcd.print(" ");
  592.   lcd.print(actualMP3);
  593. }
  594.  
  595. void kiir3(){
  596.   lcd.clear();
  597.   lcd.print(" Remote control");    
  598.   lcd.setCursor(0,1);
  599.   lcd.print(counter/10+1);
  600.   lcd.print("-");
  601.   lcd.print(counter-(counter/10)*10+1);
  602.   lcd.print(" ");
  603.   lcd.print(remoteData[counter]);
  604. }
  605.  
  606. void kiir() {
  607.   if (setting==false) {
  608.     lcd.setCursor(0,0);
  609.     lcd.print("Timer: ");
  610.     lcd.print(timerNum);
  611.     lcd.setCursor(8,0);
  612.     if (timer[timerNum]!=0) {  // Whether current timer is active
  613.       lcd.print("  Active");
  614.     } else {
  615.       if (riaszt[timerNum]==true) {
  616.         lcd.print("  ALARM ");
  617.       } else {
  618.         lcd.print("  ------");
  619.       }
  620.     }
  621.   } else {
  622.     if (setActual==false) {
  623.       lcd.setCursor(0,0);
  624.       lcd.print("Timer: ");
  625.       lcd.print(timerNum);
  626.       lcd.setCursor(8,0);
  627.       lcd.print(" Setting");
  628.     } else {
  629.       lcd.setCursor(0,0);
  630.       lcd.print("Setting ");
  631.       lcd.setCursor(8,0);
  632.       lcd.print("Timer: ");
  633.       lcd.print(timerNum);
  634.     }
  635.   }
  636.   lcd.setCursor(0,1);
  637.   convert(timer[timerNum]);    // seconds -> hour, minute, second format
  638.   lcd.print(ora);
  639.   lcd.print(":");
  640.   if (perc<10) lcd.print("0");
  641.   lcd.print(perc);
  642.   lcd.print(":");
  643.   if (sec<10) lcd.print("0");
  644.   lcd.print(sec);
  645.   lcd.print("     ");
  646.   convert(timerKezd[timerNum]);    // seconds -> hour, minute, second format
  647.   lcd.print(ora);
  648.   lcd.print(":");
  649.   if (perc<10) lcd.print("0");
  650.   lcd.print(perc);
  651. //  lcd.print(":");
  652. //  if (sec<10) lcd.print("0");
  653. //  lcd.print(sec);
  654. }
  655.  
  656. void convert(unsigned int ido) {  // seconds -> hour, minute, second format
  657.   ora=ido/3600;
  658.   ido=ido-ora*3600;
  659.   perc=ido/60;
  660.   sec=ido-perc*60;
  661. }
  662.  
  663. void tick() {   // Counter per second
  664.   if (dispOff!=0) {
  665.     dispOff--;
  666.     if (dispOff==0) shift(0);
  667.   }
  668.   for (byte i=1;i<10;i++){    // We take the timers in a row and if they are not zero, we reduce their value
  669.     if (timer[i]!=0) {
  670.       timer[i]--;
  671.       if (timer[i]==0) {    // Time has elapsed, alarm indicator setting
  672.         riaszt[i]=true;
  673.         setting=false;   // clear setting
  674.         settingVolume=false;   // delete secondary setting
  675.         kiir();
  676.       }
  677.     }
  678.   }
  679.   if (alarmNum==0) {    // No active alarm, check for background
  680.     for (byte i=1;i<10;i++){    // We take the timers in order
  681.        if (riaszt[i]==true) {
  682.         alarmNum=i;
  683.         timerNum=i;
  684.         shift(kari[timerNum]);
  685.         dispOff=0;
  686.         setting=false;   // clear setting
  687.         settingVolume=false;   // delete secondary setting
  688.         kiir();
  689.         myDFPlayer.playFolder(lang, 10+alarmNum);
  690.         Serial.print("lang: ");
  691.         Serial.print(lang);
  692.         Serial.print(" 10+alamrmNum ");
  693.         Serial.print(10+alarmNum);
  694.         Serial.print(" PLAY2 (alarmNum): ");
  695.         Serial.println(alarmNum);
  696.        }
  697.     }
  698.   }
  699.   if (settingVolume==false and setVol==false) kiir();   // Volume or Brightness uses another ejection
  700. }  // end tick
  701.  
  702. void shift(byte v){
  703.   shiftOut(DOUT, CLK, LSBFIRST, v);
  704.   delay(1);
  705.   digitalWrite(NLE, LOW);
  706.   delay(1);
  707.   digitalWrite(NLE, HIGH);
  708. }
  709.  
  710.  
  711. void pressButton() {
  712.   readingButton = digitalRead(encButton);
  713.   if (readingButton==LOW and reading==true) {
  714.     buttonCounter++;
  715.     if ((millis() - lastDebounceTime) > debounceDelay) {  // Is the prell time out?
  716.       buttonShort=true;
  717.     }
  718.     if ((millis() - lastDebounceTime) > longPressDelay) {
  719.       buttonLong=true;
  720.       buttonShort=false;
  721.     }
  722.   }
  723.   if (readingButton==HIGH) {
  724.     lastDebounceTime=millis();
  725.     buttonCounter=0;
  726.     reading=true;
  727.   }
  728. }
  729.  
  730. void pressButton1() {
  731.   readingButton1 = digitalRead(Button);
  732.   if (readingButton1==LOW and reading1==true) {
  733.     buttonCounter1++;
  734.     if ((millis() - lastDebounceTime1) > debounceDelay) {
  735.       buttonShort1=true;
  736.     }
  737.     if ((millis() - lastDebounceTime1) > longPressDelay) {
  738.       buttonLong1=true;
  739.       buttonShort1=false;
  740.     }
  741.   }
  742.   if (readingButton1==HIGH) {
  743.     lastDebounceTime1=millis();
  744.     buttonCounter1=0;
  745.     reading1=true;
  746.   }
  747. }
  748.  
  749. void ment() {
  750.   Serial.println("mentés");
  751.   for (byte i=1;i<10;i++){
  752.     EEPROM.put(i*2, timerKezd[i]);
  753.     EEPROM.write(i+30,timerMP3[i]);   // The MP3 file number assigned to the timers
  754.   }
  755. }
  756.  
  757. void langWorld(byte num){
  758.   if (num==1){
  759.     if (lang==1) lcd.print("Brightness: ");
  760.     if (lang==2) lcd.print("Helligkeit: ");
  761.     if (lang==3) lcd.print("Luminosite: ");
  762.     if (lang==4) lcd.print("Brillo: ");
  763.     if (lang==5) lcd.print("Fenyero: ");
  764.   }
  765.   if (num==2){
  766.     if (lang==1) lcd.print("Volume: ");
  767.     if (lang==2) lcd.print("Volumen: ");
  768.     if (lang==3) lcd.print("Le volume: ");
  769.     if (lang==4) lcd.print("Volume: ");
  770.     if (lang==5) lcd.print("Hangero: ");
  771.   }
  772.   if (num==3){
  773.     if (lang==1) lcd.print("Language: ");
  774.     if (lang==2) lcd.print("Sprache: ");
  775.     if (lang==3) lcd.print("Langue: ");
  776.     if (lang==4) lcd.print("Idioma: ");
  777.     if (lang==5) lcd.print("Nyelv: ");
  778.   }
  779.   if (num==4){
  780.     if (lang==1) lcd.print("English");
  781.     if (lang==2) lcd.print("Deutsche");
  782.     if (lang==3) lcd.print("Francais");
  783.     if (lang==4) lcd.print("Espanol");
  784.     if (lang==5) lcd.print("Magyar");
  785.   }
  786. }
  787.  
  788. void langSet(){
  789.   while(digitalRead(encButton)){
  790.     result = r.process();
  791.     if (result==DIR_CCW and lang<5) {
  792.       lang++;
  793.       lcd.clear();
  794.       lcd.setCursor(2,0);
  795.       langWorld(3);
  796.       lcd.print(lang);
  797.       lcd.setCursor(2,1);
  798.       langWorld(4);
  799.     }
  800.     if (result==DIR_CW and lang>1) {
  801.       lang--;
  802.       lcd.clear();
  803.       lcd.setCursor(2,0);
  804.       langWorld(3);
  805.       lcd.print(lang);
  806.       lcd.setCursor(2,1);
  807.       langWorld(4);
  808.     }
  809.   }
  810. }
  811.  
  812. void chkRemote(){
  813.   if (mySwitch.available()) {
  814.     value=mySwitch.getReceivedValue();
  815.     Serial.print("Received ");
  816.     //Serial.print( mySwitch.getReceivedValue() );
  817.     Serial.print(value);
  818.     Serial.print(" / ");
  819.     Serial.print( mySwitch.getReceivedBitlength() );
  820.     Serial.print("bit. Delay:");
  821.     Serial.print( mySwitch.getReceivedDelay() );
  822.     Serial.print(" Protocol: ");
  823.     Serial.print( mySwitch.getReceivedProtocol() );
  824.     Serial.print(" Byte: ");
  825.     Serial.print(value & 0xFF);
  826.     Serial.print(" - ");
  827.     Serial.print((value >> 8) & 0xFF);
  828.     Serial.print(" - ");
  829.     Serial.print((value >> 16) & 0xFF);
  830.     Serial.print(" - ");
  831.     Serial.println((value >> 24) & 0xFF);
  832.  
  833.     mySwitch.resetAvailable();
  834.   }
  835. }
  836.  
  837. void remoteSet(){
  838.   delay(1000);
  839.   while(!digitalRead(Button));    // waiting for the button to be released
  840.   counter=0;
  841.   while(digitalRead(Button)){
  842.     value==0;
  843.     chkRemote();
  844.     if (value!=0){
  845.       remoteData[counter]=value;
  846.       value=0;
  847.       kiir3();
  848.     }
  849.     result = r.process();
  850.     if (result==DIR_CCW and counter<19) {
  851.       counter++;
  852.       kiir3();
  853.     }
  854.     if (result==DIR_CW and counter>0) {
  855.       counter--;
  856.       kiir3();
  857.     }
  858.   }
  859.   for (byte i=0;i<20;i++){
  860.     EEPROM.put(40+i*4, remoteData[i]);
  861.   }
  862. }
  863.  
  864.  
  865. // end program code
  866.  
  867. // Languages:
  868. // 1. English
  869. // 2. German
  870. // 3. French
  871. // 4. Spanish
  872. // 5. Hungarian
  873. //
  874. // 1. English speaking
  875. // 01. Welcome! Good luck using the nine channel timer.
  876. // 02. The first timer started.
  877. // 03. The second timer started.
  878. // 04. The third timer started.
  879. // 05. The fourth timer has started.
  880. // 06. The fifth timer has started.
  881. // 07. The sixth timer has started.
  882. // 08. The seventh timer has started.
  883. // 09. The eighth timer has started.
  884. // 10. The ninth timer has started.
  885. // 11. The first timer has expired.
  886. // 12. The second timer has expired.
  887. // 13. The third timer has expired.
  888. // 14. The fourth timer has expired.
  889. // 15. The fifth timer has expired.
  890. // 16. The sixth timer has expired.
  891. // 17. The seventh timer has expired.
  892. // 18. The eighth timer has expired.
  893. // 19. The ninth timer has expired.
  894. //
  895. // 2. German speaking
  896. // 01. Herzlich willkommen! Viel Glück mit dem 9-Kanal-Timer.
  897. // 02. Der erste Timer ist gestartet.
  898. // 03. Der zweite Timer ist gestartet.
  899. // 04. Der dritte Timer ist gestartet.
  900. // 05. Der vierte Timer ist gestartet.
  901. // 06. Der fünfte Timer ist gestartet.
  902. // 07. Der sechste Timer ist gestartet.
  903. // 08. Der siebte Timer ist gestartet.
  904. // 09. Der achte Timer ist gestartet.
  905. // 10. Der neunte Timer ist gestartet.
  906. // 11. Der erste Timer ist abgelaufen.
  907. // 12. Der zweite Timer ist abgelaufen.
  908. // 13. Der dritte Timer ist abgelaufen.
  909. // 14. Der vierte Timer ist abgelaufen.
  910. // 15. Der fünfte Timer ist abgelaufen.
  911. // 16. Der sechste Timer ist abgelaufen.
  912. // 17. Der siebte Timer ist abgelaufen.
  913. // 18. Der achte Timer ist abgelaufen.
  914. // 19. Der neunte Timer ist abgelaufen.
  915. //
  916. // 3. French speaking
  917. // 01. Bienvenue! Bonne chance pour l'utilisation de la minuterie à neuf canaux.
  918. // 02. Le premier timer a démarré.
  919. // 03. Le deuxième timer a démarré.
  920. // 04. La troisième minuterie a commencé.
  921. // 05. La quatrième minuterie a démarré.
  922. // 06. La cinquième minuterie a commencé.
  923. // 07. La sixième minuterie a commencé.
  924. // 08. La septième minuterie a commencé.
  925. // 09. La huitième minuterie a commencé.
  926. // 10. La neuvième minuterie a commencé.
  927. // 11. Le premier temporisateur a expiré.
  928. // 12. La deuxième minuterie a expiré.
  929. // 13. La troisième minuterie a expiré.
  930. // 14. La quatrième minuterie a expiré.
  931. // 15. La cinquième minuterie a expiré.
  932. // 16. La sixième minuterie a expiré.
  933. // 17. La septième minuterie a expiré.
  934. // 18. La huitième minuterie a expiré.
  935. // 19. La neuvième minuterie a expiré.
  936. //
  937. // 4. Spanish speaking
  938. // 01. ¡Bienvenidos! Buena suerte con el temporizador de nueve canales.
  939. // 02. El primer temporizador ha comenzado.
  940. // 03. El segundo temporizador ha comenzado.
  941. // 04. El tercer temporizador ha comenzado.
  942. // 05. El cuarto temporizador ha comenzado.
  943. // 06. El quinto temporizador ha comenzado.
  944. // 07. El sexto temporizador ha comenzado.
  945. // 08. El séptimo temporizador ha comenzado.
  946. // 09. El octavo temporizador ha comenzado.
  947. // 10. El noveno temporizador ha comenzado.
  948. // 11. El primer temporizador ha expirado.
  949. // 12. El segundo temporizador ha expirado.
  950. // 13. El tercer temporizador ha expirado.
  951. // 14. El cuarto temporizador ha expirado.
  952. // 15. El quinto temporizador ha expirado.
  953. // 16. El sexto temporizador ha expirado.
  954. // 17. El séptimo temporizador ha expirado.
  955. // 18. El octavo temporizador ha expirado.
  956. // 19. El noveno temporizador ha expirado.
  957. //
  958. // 5. Hungarian speaking
  959. // 01. Üdvözöllek! Sok sikert a kilenc csatornás időzítő használatához.
  960. // 02. Az első időzítő elindult.
  961. // 03. A második időzítő elindult.
  962. // 04. A harmadik időzítő elindult.
  963. // 05. A negyedik időzítő elindult.
  964. // 06. Az ötödik időzítő elindult.
  965. // 07. A hatodik időzítő elindult.
  966. // 08. A hetedik időzítő elindult.
  967. // 09. A nyolcadik időzítő elindult.
  968. // 10. A kilencedik időzítő elindult.
  969. // 11. Lejárt az első időzítő.
  970. // 12. Lejárt a második időzítő.
  971. // 13. Lejárt a harmadik időzítő.
  972. // 14. Lejárt a negyedik időzítő.
  973. // 15. Lejárt az ötödik időzítő.
  974. // 16. Lejárt a hatodik időzítő.
  975. // 17. Lejárt a hetedik időzítő.
  976. // 18. Lejárt a nyolcadik időzítő.
  977. // 19. Lejárt a kilencedik időzítő.
  978. //
  979. // end text
  980.  
  981. customchar.h
  982.  
  983. byte s0[8] = {
  984.   B00000,
  985.   B00000,
  986.   B00000,
  987.   B00000,
  988.   B00000,
  989.   B00000,
  990.   B00000,
  991. };
  992.  
Add Comment
Please, Sign In to add comment