极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 26316|回复: 12

写了几天的小制作:不起床就引爆“炸弹”的闹钟

[复制链接]
发表于 2013-1-18 00:36:01 | 显示全部楼层 |阅读模式
本帖最后由 wasdpkj 于 2013-1-18 00:41 编辑

创意来自:http://www.shejipi.com/7965.html
项目名字:《不起床就引爆“炸弹”的闹钟》
你可以像普通闹钟一样,设置好闹钟时间。
但时间到后,30秒倒计时开始,你要在这个时间内选择切断三根线中的一条(随机),期间会有灯光闪烁,切错爆炸,切对则成功解除危险!              
   
还增加简单定时功能,增加了arduino端系统时间的设置,时间设置全靠红外遥控器。

演示视频:



面包板如下:用到了1307时钟模块,1602用来显示,红外遥控




程序很繁琐,自己都有点看不懂了(注释什么的更乱,可以无视),主要是倒计时当时设计的很笨,但可以用,后来就懒得改了



所用到库在文章最后面

  1. #include <IRremote.h>
  2. #include <LiquidCrystal.h>
  3. #include <OneWire.h>
  4. #include <Wire.h>
  5. #include <DS1307.h>
  6. #include <EEPROM.h>

  7. #define EEPROM_write(address, p) {int i = 0; byte *pp = (byte*)&(p);for(; i < sizeof(p); i++) EEPROM.write(address+i, pp[i]);}
  8. #define EEPROM_read(address, p)  {int i = 0; byte *pp = (byte*)&(p);for(; i < sizeof(p); i++) pp[i]=EEPROM.read(address+i);}
  9. #define DAO 2
  10. #define BONG 4

  11. boolean  C2 = false, C3 = false;                //C2、C3

  12. /*----EEPROM---*/
  13. struct config_type
  14. {
  15.     int EEPROMshi;
  16.     int EEPROMfen;
  17.     int EEPROMmin;
  18.     int EEPROMtem;
  19. };

  20. /*-------time------*/
  21. String comdata = "";  //串口数据缓存
  22. int numdata[7] = {0}, j = 0, mark = 0;
  23. int rtc[7];

  24. int timenian, timeyue, timeri, timeshi, timefen, timemiao, timezhou;        //时钟

  25. int sheNIAN, sheYUE, sheRI, sheSHI, sheFEN, sheMIAO, sheZHOU;
  26. int xuannum = 0;

  27. boolean  she = false, xuan = false, sheDOWN = false, sheUP = false, sheSTA = false;
  28. /*-------timing----*/

  29. boolean BONGshiup = false, BONGshidown = true;                //定时按钮-时
  30. boolean BONGfenup = false, BONGfendown = false;                //定时按钮-分

  31. boolean DAOsetno =  false;                //定时-执行
  32. boolean DAOsetup =  false, DAOsetdown = false;        //定时

  33. boolean DAOtimesta = false;        //计时状态位

  34. int DAOsettime, DAOnomtime;                //所需定时(分钟)
  35. int DAOtimea, DAOtimeb;                //初始时间、时间差

  36. int DAOjishu = 0;                                //总计时间

  37. int DAOTIMEDT = 10;                        //定时

  38. int BONGsetshi, BONGsetfen, BONGnomshi, BONGnomfen;        //闹钟

  39. int TIMEEEP;                //设置检查EEPROM频率

  40. int TIMELCDa = 1, TIMELCDb = 1, TIMELCDc = 1, TIMELCDd = 1;

  41. int TIMEIR = 1;
  42. /*-------LCD------*/
  43. LiquidCrystal lcd(10 , 9, 8, 7, 6, 5);//设置接口

  44. boolean lcda = false;
  45. boolean lcdb = false;
  46. boolean lcdbsta = false;
  47. boolean lcdc = false;
  48. boolean lcdcsta = false;
  49. boolean lcdd = false;

  50. /*-------ir------*/
  51. int RECV_PIN = A0;                //红外输入

  52. int i;

  53. IRrecv irrecv(RECV_PIN);
  54. decode_results results;
  55. /*----BONGsta----*/
  56. boolean BONGsta = false, STARTbong = false, OK = false, BAD = false, STAclear = false,TESTsta = false;
  57. boolean a1, a2, a3;
  58. int TIMEhaha = 30;

  59. int SUIJI;

  60. int STAa, STAb, NUMbong, Clear = 0;

  61. int NUMdao = 9;

  62. int DAOmiao,DAOmin;


  63. void setup()
  64. {
  65.     Serial.begin(9600);

  66.     config_type config_readback;
  67.     EEPROM_read(0, config_readback);

  68.     DAOsettime = config_readback.EEPROMmin;
  69.     DAOnomtime = config_readback.EEPROMmin;
  70.     BONGsetshi = config_readback.EEPROMshi;
  71.     BONGsetfen = config_readback.EEPROMfen;
  72.     BONGnomshi = config_readback.EEPROMshi;
  73.     BONGnomfen = config_readback.EEPROMfen;

  74.     pinMode(DAO, OUTPUT); //C2
  75.     pinMode(BONG, OUTPUT); //C3

  76.     pinMode(A1, INPUT); //C3
  77.     pinMode(A2, INPUT); //C3
  78.     pinMode(A3, INPUT); //C3

  79.     lcd.begin(16, 2);                                 //初始化LCD
  80.     lcd.setCursor(0, 0) ;
  81.     lcd.print("BONG!Alarm Clock");       //显示文字
  82.     lcd.setCursor(0, 1) ;
  83.     lcd.print("-----By PKJ-----");       //显示文字
  84.     delay(2000);                                                 //延时

  85.     irrecv.enableIRIn();                                 //开始采集
  86. }


  87. void loop()
  88. {
  89.     SUIJI = random(1, 4);

  90.     a1 = digitalRead(A1);
  91.     a2 = digitalRead(A2);
  92.     a3 = digitalRead(A3);

  93.     digitalWrite(DAO, C2); //C2
  94.     digitalWrite(BONG, C3); //C3

  95.     xuan = false;
  96.     sheDOWN = false;
  97.     sheUP = false;

  98.     DAOsetno =  false;
  99.     DAOsetup =  false;
  100.     DAOsetdown = false;

  101.     BONGshiup =  false;
  102.     BONGshidown = false;
  103.     BONGfenup =  false;
  104.     BONGfendown = false;

  105.     /*==================Time======================*/
  106.     RTC.get(rtc, true);

  107.     timenian = rtc[6];
  108.     timeyue = rtc[5];
  109.     timeri = rtc[4];
  110.     timezhou = rtc[3];
  111.     timeshi = rtc[2];
  112.     timefen = rtc[1];
  113.     timemiao = rtc[0];


  114.     /*=================红外控制=================*/
  115.     if (irrecv.decode(&results))
  116.     {
  117.         voir();
  118.     }

  119.     /*==============End-红外控制=================*/


  120.         /*===============设置时钟================*/
  121.     /*--------------------时间范围-----------------*/       
  122.     if(sheNIAN <= 2000)
  123.     {
  124.         sheNIAN = 2000;
  125.     }

  126.     if(sheYUE > 12)
  127.     {
  128.         sheYUE = 1;
  129.     }
  130.     if(sheYUE < 1)
  131.     {
  132.         sheYUE = 12;
  133.     }

  134.     if(sheRI > 31)
  135.     {
  136.         sheRI = 1;
  137.     }
  138.     if(sheRI < 1)
  139.     {
  140.         sheRI = 31;
  141.     }

  142.     if (sheSHI > 23)
  143.     {
  144.         sheSHI = 0;
  145.     }
  146.     if (sheSHI < 0)
  147.     {
  148.         sheSHI = 23;
  149.     }

  150.     if (sheFEN > 59)
  151.     {
  152.         sheFEN = 0;
  153.     }
  154.     if (sheFEN < 0)
  155.     {
  156.         sheFEN = 59;
  157.     }

  158.     if (sheZHOU > 7)
  159.     {
  160.         sheZHOU = 1;
  161.     }
  162.     if (sheZHOU < 1)
  163.     {
  164.         sheZHOU = 7;
  165.     }
  166.    
  167.     /*----------------end-时间范围-----------------*/       
  168.    
  169.     if (she == true)
  170.     {
  171.         RTC.stop();
  172.         sheSTA = true;

  173.         if(xuan == true)
  174.         {
  175.             xuannum++;
  176.         }

  177.         if(xuannum >= 7)
  178.         {
  179.             xuannum = 1;
  180.         }

  181.         if(xuannum == 1)
  182.         {
  183.             if(sheUP == true)
  184.             {
  185.                 sheNIAN++;
  186.             }
  187.             if(sheDOWN == true)
  188.             {
  189.                 sheNIAN--;
  190.             }
  191.         }

  192.         if(xuannum == 2)
  193.         {
  194.             if(sheUP == true)
  195.             {
  196.                 sheYUE++;
  197.             }
  198.             if(sheDOWN == true)
  199.             {
  200.                 sheYUE--;
  201.             }
  202.         }

  203.         if(xuannum == 3)
  204.         {
  205.             if(sheUP == true)
  206.             {
  207.                 sheRI++;
  208.             }
  209.             if(sheDOWN == true)
  210.             {
  211.                 sheRI--;
  212.             }
  213.         }
  214.         if(xuannum == 4)
  215.         {
  216.             if(sheUP == true)
  217.             {
  218.                 sheSHI++;
  219.             }
  220.             if(sheDOWN == true)
  221.             {
  222.                 sheSHI--;
  223.             }
  224.         }

  225.         if(xuannum == 5)
  226.         {
  227.             if(sheUP == true)
  228.             {
  229.                 sheFEN++;
  230.             }
  231.             if(sheDOWN == true)
  232.             {
  233.                 sheFEN--;
  234.             }
  235.         }

  236.         if(xuannum == 6)
  237.         {
  238.             if(sheUP == true)
  239.             {
  240.                 sheZHOU++;
  241.             }
  242.             if(sheDOWN == true)
  243.             {
  244.                 sheZHOU--;
  245.             }
  246.         }

  247.     }

  248.     else
  249.     {
  250.         if(sheSTA == true)
  251.         {
  252.             Serial.println("--OK--");

  253.             RTC.set(DS1307_YR, sheNIAN);
  254.             RTC.set(DS1307_MTH, sheYUE);
  255.             RTC.set(DS1307_DATE, sheRI);
  256.             RTC.set(DS1307_HR, sheSHI);
  257.             RTC.set(DS1307_MIN, sheFEN);
  258.             RTC.set(DS1307_SEC, sheMIAO);
  259.             RTC.set(DS1307_DOW, sheZHOU);
  260.             RTC.start();
  261.             sheSTA = false;
  262.         }
  263.         xuannum = 0;
  264.     }

  265.         /*===============end-设置时钟============*/


  266.     /*==================BONGsta======================*/
  267.    
  268.     if(STAclear == true)
  269.     {
  270.         if(timemiao != STAb)
  271.         {
  272.             Clear++;
  273.         }
  274.         if(Clear >= 10)
  275.         {
  276.             C2 = false;
  277.             C3 = false;
  278.             Clear = 0;
  279.             STAclear = false;
  280.         }
  281.     }

  282.     if(BONGsta == true && STARTbong == true)
  283.     {
  284.         if(TIMEhaha == 30)
  285.         {
  286.             NUMbong = SUIJI;
  287.         }

  288.         if(timemiao != STAa)
  289.         {
  290.             TIMEhaha--;
  291.             C2 = !C2;
  292.         }
  293.     }

  294.     if(TIMEhaha <= 0)
  295.     {
  296.         BAD = true;
  297.     }

  298.     if(BONGsta == true)
  299.         switch(NUMbong)
  300.         {
  301.         case 1:
  302.             Serial.print("                                 a1");
  303.             Serial.println("");
  304.             if(a1 == false && a2 == true && a3 == true)
  305.             {
  306.                 OK = true;
  307.                 Serial.print("                                 OK");
  308.                 Serial.println("");
  309.             }
  310.             else
  311.             {
  312.                 if(!(a1 == true && a2 == true && a3 == true))
  313.                 {
  314.                     BAD = true;
  315.                     Serial.print("                                 BONG");
  316.                     Serial.println("");
  317.                 }
  318.             }
  319.             ;
  320.             break;

  321.         case 2:
  322.             Serial.print("                                 a2");
  323.             Serial.println("");
  324.             if(a1 == true && a2 == false && a3 == true)
  325.             {
  326.                 OK = true;
  327.                 Serial.print("                                 OK");
  328.                 Serial.println("");
  329.             }
  330.             else
  331.             {
  332.                 if(!(a1 == true && a2 == true && a3 == true))
  333.                 {
  334.                     BAD = true;
  335.                     Serial.print("                                 BONG");
  336.                     Serial.println("");
  337.                 }
  338.             }
  339.             ;
  340.             break;

  341.         case 3:
  342.             Serial.print("                                 a3");
  343.             Serial.println("");
  344.             if(a1 == true && a2 == true && a3 == false)
  345.             {
  346.                 OK = true;
  347.                 Serial.print("                                 OK");
  348.                 Serial.println("");
  349.             }
  350.             else
  351.             {
  352.                 if(!(a1 == true && a2 == true && a3 == true))
  353.                 {
  354.                     BAD = true;
  355.                     Serial.print("                                 BONG");
  356.                     Serial.println("");
  357.                 }
  358.             }
  359.             ;
  360.             break;
  361.         }

  362.     STARTbong = false;

  363.     if(a1 == true && a2 == true && a3 == true)
  364.     {
  365.         STARTbong = true;
  366.     }

  367.         /*=================执行================*/
  368.     if(OK == true)
  369.     {
  370.         digitalWrite(BONG, 0); //C3
  371.         delay(600);
  372.         digitalWrite(BONG, 1); //C3
  373.         delay(550);
  374.         digitalWrite(BONG, 0); //C3
  375.         delay(500);
  376.         digitalWrite(BONG, 1); //C3
  377.         delay(450);
  378.         digitalWrite(BONG, 0); //C3
  379.         delay(400);
  380.         digitalWrite(BONG, 1); //C3
  381.         delay(350);
  382.         digitalWrite(BONG, 0); //C3
  383.         delay(300);
  384.         digitalWrite(BONG, 1); //C3
  385.         delay(250);
  386.         digitalWrite(BONG, 0); //C3
  387.         delay(200);
  388.         digitalWrite(BONG, 1); //C3
  389.         delay(150);
  390.         digitalWrite(BONG, 0); //C3
  391.         delay(150);
  392.         digitalWrite(BONG, 1); //C3
  393.         delay(150);
  394.         digitalWrite(BONG, 0); //C3
  395.         delay(150);
  396.         digitalWrite(BONG, 1); //C3
  397.         delay(150);
  398.         digitalWrite(BONG, 0); //C3
  399.         delay(150);
  400.         digitalWrite(BONG, 1); //C3
  401.         delay(150);
  402.         digitalWrite(BONG, 0); //C3
  403.         delay(150);
  404.         digitalWrite(BONG, 1); //C3
  405.         delay(150);
  406.         digitalWrite(BONG, 0); //C3

  407.         TIMEhaha = 30;

  408.         C3 = false;
  409.         C2 = false;
  410.         BONGsta = false;

  411.         STAclear = true;

  412.         OK = false;
  413.         Serial.print("                                 [OK]");
  414.         Serial.println("");
  415.     }

  416.     if(BAD == true)
  417.     {
  418.         digitalWrite(BONG, 0); //C3
  419.         delay(600);
  420.         digitalWrite(BONG, 1); //C3
  421.         delay(550);
  422.         digitalWrite(BONG, 0); //C3
  423.         delay(500);
  424.         digitalWrite(BONG, 1); //C3
  425.         delay(450);
  426.         digitalWrite(BONG, 0); //C3
  427.         delay(400);
  428.         digitalWrite(BONG, 1); //C3
  429.         delay(350);
  430.         digitalWrite(BONG, 0); //C3
  431.         delay(300);
  432.         digitalWrite(BONG, 1); //C3
  433.         delay(250);
  434.         digitalWrite(BONG, 0); //C3
  435.         delay(200);
  436.         digitalWrite(BONG, 1); //C3
  437.         delay(150);
  438.         digitalWrite(BONG, 0); //C3
  439.         delay(150);
  440.         digitalWrite(BONG, 1); //C3
  441.         delay(150);
  442.         digitalWrite(BONG, 0); //C3
  443.         delay(150);
  444.         digitalWrite(BONG, 1); //C3
  445.         delay(150);
  446.         digitalWrite(BONG, 0); //C3
  447.         delay(150);
  448.         digitalWrite(BONG, 1); //C3
  449.         delay(150);
  450.         digitalWrite(BONG, 0); //C3
  451.         delay(150);
  452.         digitalWrite(BONG, 1); //C3
  453.         delay(150);
  454.         digitalWrite(BONG, 0); //C3
  455.         delay(150);
  456.         digitalWrite(BONG, 1); //C3

  457.         TIMEhaha = 30;

  458.         BONGsta = false;
  459.         C2 = false;
  460.         C3 = true;

  461.         STAclear = true;

  462.         BAD = false;
  463.         
  464.         Serial.print("                                 [BAD]");
  465.         Serial.println("");
  466.     }

  467.     delay(80);   

  468.     /*===============end-BONGsta================*/


  469.     /*================定时===================*/

  470.     if (BONGshiup == true)     //控制数值上升
  471.     {
  472.         BONGsetshi++;
  473.     }
  474.     if (BONGshidown == true)           //控制数值下降
  475.     {
  476.         BONGsetshi--;
  477.     }

  478.     if (BONGfenup == true)     //控制数值上升
  479.     {
  480.         BONGsetfen++;
  481.     }
  482.     if (BONGfendown == true)           //控制数值下降
  483.     {
  484.         BONGsetfen--;
  485.     }

  486.     if (BONGsetshi > 23)
  487.     {
  488.         BONGsetshi = 0;
  489.     }
  490.     if (BONGsetshi < 0)
  491.     {
  492.         BONGsetshi = 23;
  493.     }
  494.     if (BONGsetfen > 59)
  495.     {
  496.         BONGsetfen = 0;
  497.     }
  498.     if (BONGsetfen < 0)
  499.     {
  500.         BONGsetfen = 59;
  501.     }

  502.     if(timeshi == BONGsetshi && timefen == (BONGsetfen-1) && timemiao == 30)
  503.     {
  504.         BONGsta = true;
  505.         delay(1000);
  506.     }
  507.    
  508.     if(TESTsta == true)
  509.     {
  510.         BONGsta = true;
  511.         delay(1000);
  512.         TESTsta = false;
  513.     }
  514.    
  515.     /*================end-定时===================*/

  516.    
  517.     /*================倒计时===================*/

  518.     if (DAOsetup == true && DAOtimesta == false)     //控制数值上升
  519.     {
  520.         DAOsettime++;
  521.     }
  522.     if (DAOsetdown == true && DAOtimesta == false)           //控制数值下降
  523.     {
  524.         DAOsettime--;
  525.     }

  526.     if (DAOsettime > 30)
  527.     {
  528.         DAOsettime = 1;
  529.     }
  530.     if (DAOsettime < 1)
  531.     {
  532.         DAOsettime = 30;
  533.     }


  534.     if (DAOsetno == true && (DAOtimesta == false && C2 == false) && STAclear == false && BONGsta == false)          //C2为零时可触发计时
  535.     {
  536.         delay(20);
  537.         C2 = true;                                //开始烧水
  538.         DAOtimea = timemiao;                //计时起始位
  539.         DAOtimeb = 0;                        //十秒清零
  540.         DAOjishu = 0;                        //计数清零
  541.         DAOtimesta = true;                  //开始计时
  542.     }

  543.     else if (DAOsetno == true && (DAOtimesta == true || C2 == true))          //C2为1时或计时开始后,再次触发则停止计时、
  544.     {
  545.         delay(20);
  546.         C2 = false;
  547.         DAOtimesta = false;                  //停止计时
  548.     }

  549.     if(DAOtimesta == true)
  550.     {
  551.         if(DAOtimea >= 49)                  //以十秒为基数统计
  552.         {
  553.             if(timemiao <= 59 && timemiao >= 49)
  554.             {
  555.                 DAOtimeb = timemiao - DAOtimea;
  556.             }
  557.             if(timemiao >= 0 && timemiao <= 9)
  558.             {
  559.                 DAOtimeb = 60 + timemiao - DAOtimea;
  560.             }
  561.         }

  562.         else
  563.         {
  564.             DAOtimeb = timemiao - DAOtimea;        //49秒以下正常计数
  565.         }

  566.     }

  567.     if(DAOtimeb >= 10)                          //十秒计时完毕后
  568.     {
  569.         DAOjishu++;                //以计时值得到总时间
  570.         DAOtimeb = 0;                                //归零
  571.         DAOtimea = timemiao;                //开始新一轮计时
  572.     }

  573.     if(DAOsettime <= DAOjishu/6)          //大于设置值
  574.     {
  575.         DAOtimesta = false;                      //停止计时
  576.         C2 = false;                                //停止
  577.     }

  578.     if(DAOtimesta == false)          //必要的清零
  579.     {
  580.         DAOtimeb = 0;
  581.         DAOjishu = 0;
  582.     }
  583.    
  584.     DAOmin=((DAOsettime * 6 - DAOjishu)-1) / 6;

  585.     DAOmiao=((DAOsettime * 6 - DAOjishu)-1) % 6;
  586.    
  587.     if(DAOtimesta == true)
  588.     {
  589.         if(timemiao != STAa)
  590.         {
  591.             C2 = !C2;
  592.             NUMdao--;
  593.         }
  594.         if(NUMdao<0)
  595.         {
  596.         NUMdao=9;
  597.         }
  598.     }
  599.     else
  600.     {
  601.     NUMdao=9;
  602.     }

  603.     /*=============End-倒计时===================*/

  604.    
  605.    
  606.     /*==================EEPROM==================*/
  607.     if (TIMEEEP <= 10)                          //设置EEPROM检查刷新频率
  608.     {
  609.         TIMEEEP++;
  610.     }

  611.     else
  612.     {
  613.         if((BONGnomshi != BONGsetshi) || (BONGnomfen != BONGsetfen) || (DAOsettime != DAOnomtime))
  614.         {
  615.             eeprom_test();
  616.             BONGnomshi = BONGsetshi;
  617.             BONGnomfen = BONGsetfen;
  618.             DAOnomtime = DAOsettime;
  619.         }
  620.     }

  621.     /*================endEEPROM================*/


  622.     /*==================显示===================*/

  623.     {
  624.         if(DAOsetup == true || DAOsetdown == true)                  //触发
  625.         {
  626.             TIMELCDa = 1;
  627.             lcda = true;
  628.         }

  629.         if(lcda == true)
  630.         {
  631.             volcda();
  632.         }
  633.         /*--------------------------------------------------------*/


  634.         /*--------------------------------------------------------*/

  635.         if(BONGshiup == true || BONGshidown == true || BONGfendown == true || BONGfenup == true)                  //触发
  636.         {
  637.             TIMELCDd = 1;
  638.             lcdd = true;
  639.         }

  640.         if(lcdd == true)
  641.         {
  642.             volcdd();
  643.         }

  644.         /*--------------------------------------------------------*/

  645.         voLCD();

  646.     }

  647.     STAb = timemiao;
  648.     STAa = timemiao;
  649.     /*===============End-显示===================*/

  650.     Serial.print("                    TIMEhaha:");
  651.     Serial.print(TIMEhaha);
  652.     Serial.println("");

  653.     Serial.print("                    BONGsta:");
  654.     Serial.print(BONGsta);
  655.     Serial.println("");

  656.     Serial.print("                                              Clear: ");
  657.     Serial.print(Clear);
  658.     Serial.println("");

  659.     Serial.print("                                 NUMbong: ");
  660.     Serial.print(NUMbong);
  661.     Serial.println("");

  662.     Serial.print("                                 STARTbong: ");
  663.     Serial.print(STARTbong);
  664.     Serial.println("");
  665.    
  666.     Serial.print("                                 OK: ");
  667.     Serial.print(OK);
  668.     Serial.println("");
  669.    
  670.     Serial.print("                                 BAD: ");
  671.     Serial.print(BAD);
  672.     Serial.println("");

  673.    

  674. }


  675. void volcda()
  676. {
  677.     if (TIMELCDa <= 12 && lcda == true)                          //设置刷新频率
  678.     {
  679.         TIMELCDa++;
  680.     }

  681.     else
  682.     {
  683.         lcda = false;
  684.         TIMELCDa = 1;
  685.     }
  686. }


  687. void volcdd()
  688. {
  689.     if (TIMELCDd <= 20 && lcdd == true)                          //设置刷新频率
  690.     {
  691.         TIMELCDd++;
  692.     }

  693.     else
  694.     {
  695.         lcdd = false;
  696.         TIMELCDd = 1;
  697.     }
  698. }


  699. void voLCD()
  700. {
  701.     lcd.clear();                                                //清屏

  702.     /*-----------------------显示时间---------------------*/
  703.     lcd.setCursor(0, 0) ;
  704.     lcd.print(timenian);
  705.     lcd.print("-");
  706.     if(timeyue <= 9)
  707.     {
  708.         lcd.print("0");
  709.         lcd.print(timeyue);
  710.     }
  711.     else
  712.     {
  713.         lcd.print(timeyue);
  714.     }
  715.     lcd.print("-");
  716.     if(timeri <= 9)
  717.     {
  718.         lcd.print("0");
  719.         lcd.print(timeri);
  720.     }
  721.     else
  722.     {
  723.         lcd.print(timeri);
  724.     }
  725.     lcd.print(" ");

  726.     lcd.setCursor(11, 0) ;
  727.     if(timeshi <= 9)
  728.     {
  729.         lcd.print("0");
  730.         lcd.print(timeshi);
  731.     }
  732.     else
  733.     {
  734.         lcd.print(timeshi);
  735.     }
  736.     lcd.setCursor(13, 0) ;
  737.     if(timemiao % 2 == 0)
  738.     {
  739.         lcd.print(":");
  740.     }
  741.     else
  742.     {
  743.         lcd.print(" ");
  744.     }
  745.     lcd.setCursor(14, 0) ;
  746.     if(timefen <= 9)
  747.     {
  748.         lcd.print("0");
  749.         lcd.print(timefen);
  750.     }
  751.     else
  752.     {
  753.         lcd.print(timefen);
  754.     }


  755.     /*---------------sheTIME----------------*/
  756.     if(she == false)
  757.     {
  758.         lcd.setCursor(0, 1) ;
  759.         lcd.print("Set Time : ");
  760.     }
  761.     else
  762.     {
  763.         switch(xuannum)
  764.         {
  765.         case 0:
  766.             lcd.setCursor(0, 1) ;
  767.             lcd.print("Switch[0]");
  768.             break;
  769.         case 1:
  770.             lcd.setCursor(0, 1) ;
  771.             lcd.print("YEAR:");
  772.             lcd.print(sheNIAN);
  773.             break;
  774.         case 2:
  775.             lcd.setCursor(0, 1) ;
  776.             lcd.print("MON.:");
  777.             lcd.print(sheYUE);
  778.             break;
  779.         case 3:
  780.             lcd.setCursor(0, 1) ;
  781.             lcd.print("DATA:");
  782.             lcd.print(sheRI);
  783.             break;
  784.         case 4:
  785.             lcd.setCursor(0, 1) ;
  786.             lcd.print("HOUR:");
  787.             lcd.print(sheSHI);
  788.             break;
  789.         case 5:
  790.             lcd.setCursor(0, 1) ;
  791.             lcd.print("MIN.:");
  792.             lcd.print(sheFEN);
  793.             break;
  794.         case 6:
  795.             lcd.setCursor(0, 1) ;
  796.             lcd.print("WEEK:");
  797.             lcd.print(sheZHOU);
  798.             break;
  799.         }
  800.     }
  801.     /*--------------------------------------------------------*/
  802.     lcd.setCursor(11, 1) ;
  803.     if(BONGsetshi <= 9)
  804.     {
  805.         lcd.print("0");
  806.         lcd.print(BONGsetshi);
  807.     }
  808.     else
  809.     {
  810.         lcd.print(BONGsetshi);
  811.     }
  812.     lcd.setCursor(13, 1) ;
  813.     lcd.print(":");
  814.     lcd.setCursor(14, 1) ;
  815.     if(BONGsetfen <= 9)
  816.     {
  817.         lcd.print("0");
  818.         lcd.print(BONGsetfen);
  819.     }
  820.     else
  821.     {
  822.         lcd.print(BONGsetfen);
  823.     }

  824.     /*-------------------------STABONG--------------------------------*/

  825.     if(STAclear == true)
  826.     {
  827.         lcd.setCursor(0, 1) ;
  828.         if(timemiao % 2 == 0)
  829.         {
  830.             if(C3 == true)
  831.             {
  832.                 lcd.print("!!!!!!BONG!!!!!!");
  833.             }
  834.             else
  835.             {
  836.                 lcd.print("^_^^_^Clean^_^^_^");
  837.             }
  838.         }
  839.         else
  840.         {
  841.             lcd.print("                ");
  842.         }

  843.     }

  844.     /*------------------------设置二路时间----------------------------*/
  845.     if (lcda == true)
  846.     {
  847.         lcd.setCursor(10, 1) ;
  848.         lcd.print("[");
  849.         if(DAOsettime <= 9)
  850.         {
  851.             lcd.print("0");
  852.             lcd.setCursor(11, 1) ;
  853.         }
  854.         else
  855.         {
  856.             lcd.setCursor(10, 1) ;
  857.         }
  858.         lcd.print(DAOsettime);
  859.         lcd.setCursor(12, 1) ;
  860.         lcd.print("min] ");
  861.     }

  862.     /*----------------------显示设置3路时间--------------------------*/

  863.     if (lcdd == true)
  864.     {
  865.         lcd.setCursor(10, 1) ;
  866.         lcd.print("=");
  867.         lcd.setCursor(11, 1) ;
  868.         if(BONGsetshi <= 9)
  869.         {
  870.             lcd.print("0");
  871.             lcd.print(BONGsetshi);
  872.         }
  873.         else
  874.         {
  875.             lcd.print(BONGsetshi);
  876.         }
  877.         lcd.setCursor(13, 1) ;
  878.         lcd.print(":");
  879.         lcd.setCursor(14, 1) ;
  880.         if(BONGsetfen <= 9)
  881.         {
  882.             lcd.print("0");
  883.             lcd.print(BONGsetfen);
  884.         }
  885.         else
  886.         {
  887.             lcd.print(BONGsetfen);
  888.         }
  889.     }

  890.     /*------------------------二路倒计时---------------------------*/
  891.     if(DAOtimesta == true)
  892.     {
  893.         lcd.setCursor(0, 1) ;
  894.         lcd.print("Remaining: ");
  895.         if(DAOmin <= 9)
  896.         {
  897.             lcd.print("0");
  898.             lcd.setCursor(12, 1) ;
  899.         }
  900.         else
  901.         {
  902.             lcd.setCursor(11, 1) ;
  903.         }
  904.         lcd.print(DAOmin);
  905.         lcd.setCursor(13, 1) ;
  906.         lcd.print(":");

  907.             lcd.setCursor(14, 1) ;
  908.                         lcd.print(DAOmiao);
  909.                         lcd.print(NUMdao);
  910.     }

  911.     if(BONGsta == true)
  912.     {
  913.         if(STARTbong == false && BAD == false && OK == false)
  914.         {
  915.             lcd.setCursor(0, 1) ;
  916.             lcd.print("     NO-READY   ");
  917.             delay(1200);
  918.             BONGsta = false;
  919.         }
  920.         lcd.setCursor(0, 1) ;
  921.         lcd.print("Left:[");
  922.         if(TIMEhaha <= 9)
  923.         {
  924.             lcd.print("0");
  925.             lcd.print(TIMEhaha);
  926.         }
  927.         else
  928.         {
  929.             lcd.print(TIMEhaha);
  930.         }
  931.         lcd.print("s] ");
  932.     }
  933. }


  934. void voir()
  935. {
  936.     unsigned long remote = results.value;                //设红外信号为remote

  937.     if(remote == (-1))          //溢出时
  938.     {
  939.         Serial.print("irCode: ");
  940.         Serial.print(results.value, HEX);   //输出红外线解码结果(十六进制)
  941.         Serial.print(",  bits: ");
  942.         Serial.println(results.bits);
  943.     }
  944.     switch (remote)
  945.     {
  946.     case 0xFF629D:                //CH   -开始定时
  947.         DAOsetno = true;
  948.         delay(10);
  949.         break;

  950.     case 0xFFE21D:                //CH+   -定时设置
  951.         DAOsetup = true;
  952.         delay(10);
  953.         break;

  954.     case 0xFFA25D:                //CH-   -定时设置
  955.         DAOsetdown = true;
  956.         delay(10);
  957.         break;

  958.     case 0xFF02FD:                //NEXT  -闹钟设置
  959.         BONGfenup = true;
  960.         delay(10);
  961.         break;

  962.     case 0xFF22DD:                //PREV  -闹钟设置
  963.         BONGfendown = true;
  964.         delay(10);
  965.         break;

  966.     case 0xFFA857:                //+  -闹钟设置
  967.         BONGshiup = true;
  968.         delay(10);
  969.         break;

  970.     case 0xFFE01F:                //-   -闹钟设置
  971.         BONGshidown = true;
  972.         delay(10);
  973.         break;

  974.     case 0xFF906F:                //EQ   -更改系统时钟
  975.         she = !she;
  976.         if(sheSTA == false)
  977.         {
  978.             sheNIAN = timenian;
  979.             sheYUE = timeyue;
  980.             sheRI = timeri;
  981.             sheSHI = timeshi;
  982.             sheFEN = timefen;
  983.             sheMIAO = timemiao;
  984.             sheZHOU = timezhou;
  985.         }
  986.         delay(10);
  987.         break;

  988.     case 0xFF6897:                //0   -切换时钟设置菜单
  989.         xuan = true;
  990.         delay(10);
  991.         break;
  992.     case 0xFF9867:                //100+   -调整系统时钟
  993.         sheDOWN = true;
  994.         delay(10);
  995.         break;
  996.     case 0xFFB04F:                //200+   -调整系统时钟
  997.         sheUP = true;
  998.         delay(10);
  999.         break;

  1000.     case 0xFFC23D:                //PLAY   -用以测试倒计时
  1001.         TESTsta = true;
  1002.         delay(10);
  1003.         break;

  1004.     }
  1005.     /*--------------------------------*/

  1006.     irrecv.resume();                 // 返回值
  1007. }


  1008. void eeprom_test()
  1009. {
  1010.     config_type config;                  // 定义结构变量config,并定义config的内容
  1011.     config.EEPROMshi = BONGsetshi;
  1012.     config.EEPROMfen = BONGsetfen;
  1013.     config.EEPROMmin = DAOsettime;

  1014.     EEPROM_write(0, config);         // 变量config存储到EEPROM,地址0写入
  1015. }
复制代码



本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复

使用道具 举报

发表于 2013-1-18 08:30:44 来自手机 | 显示全部楼层
库收了。。哈哈
回复 支持 反对

使用道具 举报

发表于 2013-1-18 09:17:36 | 显示全部楼层
这个创意很好!!!
回复 支持 反对

使用道具 举报

发表于 2013-1-18 09:23:17 | 显示全部楼层
每天起床心惊胆战啊
回复 支持 反对

使用道具 举报

发表于 2013-1-18 19:57:13 | 显示全部楼层
恩,不太利于身体健康,人说,醒了就直接起床的容易短命。。。要在床上赖会儿才起来比较好!
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-1-18 20:34:45 | 显示全部楼层
zcbzjx 发表于 2013-1-18 19:57
恩,不太利于身体健康,人说,醒了就直接起床的容易短命。。。要在床上赖会儿才起来比较好!

如果不想开启炸弹模式,几根线不接上也就不会启动了
回复 支持 反对

使用道具 举报

发表于 2013-1-18 20:51:32 | 显示全部楼层
wasdpkj 发表于 2013-1-18 20:34
如果不想开启炸弹模式,几根线不接上也就不会启动了

玩笑玩笑。。。挺好的应用。。。最好赶飞机,赶火车的时候启动炸弹模式。。免得耽误事
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-1-18 21:55:19 | 显示全部楼层
zcbzjx 发表于 2013-1-18 20:51
玩笑玩笑。。。挺好的应用。。。最好赶飞机,赶火车的时候启动炸弹模式。。免得耽误事

可惜目前没有真炸弹,只能拿个蜂鸣器唬唬人
回复 支持 反对

使用道具 举报

发表于 2013-1-20 09:53:50 | 显示全部楼层
这个做闹钟有点那个啥。。。应该用来做安全锁。。。两层门的那种。。第一层门打开开始倒计时。。开关拨错了。一盆水就扣下来。。。。
回复 支持 反对

使用道具 举报

发表于 2013-1-21 00:54:50 | 显示全部楼层
迷你强 发表于 2013-1-20 09:53
这个做闹钟有点那个啥。。。应该用来做安全锁。。。两层门的那种。。第一层门打开开始倒计时。。开关拨错 ...

错了,就放高压电~~
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-1-21 01:04:25 | 显示全部楼层
迷你强 发表于 2013-1-20 09:53
这个做闹钟有点那个啥。。。应该用来做安全锁。。。两层门的那种。。第一层门打开开始倒计时。。开关拨错 ...

你更能整
回复 支持 反对

使用道具 举报

发表于 2015-5-7 14:59:37 | 显示全部楼层
放烟怎么样
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|联系我们|极客工坊

GMT+8, 2026-6-17 08:17 , Processed in 0.040127 second(s), 24 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表