Advertisement
orcinus

Quick Arduino clock/email notification thingy

Dec 4th, 2012
312
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.52 KB | None | 0 0
  1. #include <ShiftLCD.h>
  2. #include <Wire.h>
  3. #include <PCF8583.h>
  4.  
  5. ShiftLCD lcd(2, 4, 3);
  6. #define LCD_BL_PIN 0x04
  7. #define LCD_LED_PIN 0x08
  8.  
  9. int correct_address = 0;
  10. PCF8583 p (0xA0);
  11.  
  12. char  serIn[6] = "0";
  13. char  mailCounter[5] = "0";
  14. int   hourSet;
  15. int   minSet;
  16. int   u;
  17. unsigned long currtime;
  18.  
  19. int startuptune[] = {
  20.   262, 196, 262, 196};
  21. int mailtune[] = {
  22.   196, 196, 262};
  23.  
  24. byte custchar[8][8] = {
  25.   {
  26.     B11111,
  27.     B11111,
  28.     B11111,
  29.     B00000,
  30.     B00000,
  31.     B00000,
  32.     B00000,
  33.     B00000
  34.   }
  35.   , {
  36.     B00000,
  37.     B00000,
  38.     B00000,
  39.     B00000,
  40.     B00000,
  41.     B11111,
  42.     B11111,
  43.     B11111
  44.   }
  45.   , {
  46.     B11111,
  47.     B11111,
  48.     B11111,
  49.     B00000,
  50.     B00000,
  51.     B11111,
  52.     B11111,
  53.     B11111
  54.   }
  55.   , {
  56.     B00000,
  57.     B00000,
  58.     B00000,
  59.     B00000,
  60.     B00000,
  61.     B00110,
  62.     B00110,
  63.     B00110
  64.   }
  65.   , {
  66.     B00000,
  67.     B00000,
  68.     B00000,
  69.     B01110,
  70.     B01110,
  71.     B01110,
  72.     B00000,
  73.     B00000
  74.   }
  75.   , {
  76.     B11111,
  77.     B11111,
  78.     B11011,
  79.     B11011,
  80.     B11111,
  81.     B11111,
  82.     B00000,
  83.     B00000
  84.   }
  85.   , {
  86.     B00000,
  87.     B00000,
  88.     B00000,
  89.     B00000,
  90.     B00000,
  91.     B00000,
  92.     B00000,
  93.     B00000
  94.   }
  95.   , {
  96.     B11111,
  97.     B11111,
  98.     B11111,
  99.     B11111,
  100.     B11111,
  101.     B11111,
  102.     B11111,
  103.     B11111
  104.   }
  105. };
  106.  
  107. byte bignums[12][2][3] = {
  108.   {
  109.     {
  110.       7, 0, 7    }
  111.     ,
  112.     {
  113.       7, 1, 7    }
  114.   }
  115.   ,{
  116.     {
  117.       0, 7, 6    }
  118.     ,
  119.     {
  120.       1, 7, 1    }
  121.   }
  122.   ,{
  123.     {
  124.       0, 0, 7    }
  125.     ,
  126.     {
  127.       7, 2, 2    }
  128.   }
  129.   ,{
  130.     {
  131.       0, 2, 7    }
  132.     ,
  133.     {
  134.       1, 1, 7    }
  135.   }
  136.   ,{
  137.     {
  138.       7, 1, 7    }
  139.     ,
  140.     {
  141.       6, 6, 7    }
  142.   }
  143.   ,{
  144.     {
  145.       7, 2, 2    }
  146.     ,
  147.     {
  148.       1, 1, 7    }
  149.   }
  150.   ,{
  151.     {
  152.       7, 2, 2    }
  153.     ,
  154.     {
  155.       7, 1, 7    }
  156.   }
  157.   ,{
  158.     {
  159.       0, 0, 7    }
  160.     ,
  161.     {
  162.       6, 7, 6    }
  163.   }
  164.   ,{
  165.     {
  166.       7, 2, 7    }
  167.     ,
  168.     {
  169.       7, 1, 7    }
  170.   }
  171.   ,{
  172.     {
  173.       7, 2, 7    }
  174.     ,
  175.     {
  176.       6, 6, 7    }
  177.   }
  178.   ,{
  179.     {
  180.       7, 0, 0    }
  181.     ,
  182.     {
  183.       7, 1, 1    }
  184.   }
  185.   ,{
  186.     {
  187.       6, 6, 6    }
  188.     ,
  189.     {
  190.       6, 6, 6    }
  191.   }
  192. };
  193.  
  194. void loadchars() {
  195.   lcd.command(64);
  196.   for (int i = 0; i < 8; i++)
  197.     lcd.createChar(i, custchar[i]);
  198.   lcd.home();
  199. }
  200.  
  201. void printbigchar(byte digit, byte col, byte row, byte symbol = 0) {
  202.   if (digit > 11) return;
  203.   for (int i = 0; i < 2; i++) {
  204.     lcd.setCursor(col*4, row + i);
  205.     for (int j = 0; j < 3; j++) {
  206.       lcd.write(bignums[digit][i][j]);
  207.     }
  208.   }
  209.   if (symbol == 0) {
  210.     lcd.setCursor(col*4 + 3, row);
  211.     lcd.write(6);
  212.     lcd.setCursor(col*4 + 3, row + 1);
  213.     lcd.write(6);
  214.   }
  215.   else if (symbol == 1) {
  216.     lcd.setCursor(col*4 + 3, row);
  217.     lcd.write(6);
  218.     lcd.setCursor(col*4 + 3, row + 1);
  219.     lcd.write(3);
  220.   }
  221.   else if (symbol == 2) {
  222.     lcd.setCursor(col*4 + 3, row);
  223.     lcd.write(4);
  224.     lcd.setCursor(col*4 + 3, row + 1);
  225.     lcd.write(4);
  226.   }
  227.   lcd.setCursor(col*4 + 4, row);
  228. }
  229.  
  230. void bigprint(float number, int col)
  231. {
  232.   printbigchar(number / 10,col,0);
  233.   printbigchar(int(number)%10,col+1,0,1);
  234.   printbigchar(int(number*10)%10,col+2,0);
  235. }
  236.  
  237. void bigclock(int time, int col, char mails[5])
  238. {
  239.   p.get_time();
  240.   printbigchar(p.hour/10,col,0);
  241.   if(p.second%2==0) printbigchar(p.hour%10,col+1,0,2);
  242.   else printbigchar(p.hour%10,col+1,0);
  243.   printbigchar(p.minute/10,col+2,0);
  244.   printbigchar(p.minute%10,col+3,0);
  245.   /*printbigchar(11,col+4,0);*/
  246.   lcd.setCursor(16,0);
  247.   if (mails[0]=='0' && mails[1]==0) lcd.print("No");
  248.   else lcd.print(mails);
  249.   lcd.setCursor(16,1);
  250.   if (mails[0]=='0' && mails[1]==0) {
  251.     lcd.print("Mail");
  252.     digitalWrite(10, LOW);
  253.   }
  254.   else lcd.print("Msgs");
  255. }
  256.  
  257. void serial()
  258. {
  259.   // ***goSerial comms***
  260.   if(Serial.available()) {
  261.     u=0;
  262.     serIn[0]=0;
  263.     while (Serial.available()>0){
  264.       serIn[u++] = Serial.read();   //read Serial        
  265.     }
  266.  
  267.     serIn[u]=0;
  268.    
  269.     // 0 => reset mail counter
  270.     if (serIn[0]=='0') {
  271.       mailCounter[0]='0';
  272.       mailCounter[1]=0;
  273.     }
  274.     // T => set time
  275.     if (serIn[0]=='T') {
  276.       p.hour=(serIn[1]-48)*10+(serIn[2]-48);
  277.       p.minute=(serIn[3]-48)*10+(serIn[4]-48);
  278.       p.second=0;
  279.       p.set_time();
  280.      
  281.       for(int i=0;i<20;i++){
  282.         lcd.scrollDisplayRight();
  283.         delay(20);
  284.       }
  285.       lcd.clear();
  286.       lcd.setCursor(1,0);
  287.       lcd.print("Time has been set!");
  288.       lcd.setCursor(7,1);
  289.       if(!(p.hour/10)) lcd.print("0");
  290.       lcd.print(p.hour); lcd.print(":");
  291.       if(!(p.minute/10)) lcd.print("0");
  292.       lcd.print(p.minute);
  293.       for(int i=0;i<20;i++){
  294.         lcd.scrollDisplayLeft();
  295.         delay(20);
  296.       }
  297.       delay(5000);
  298.         for(int i=0;i<20;i++){
  299.         lcd.scrollDisplayRight();
  300.         delay(20);
  301.       }
  302.       lcd.clear();
  303.       for(int i=0;i<20;i++){
  304.         lcd.scrollDisplayLeft();
  305.       }
  306.      
  307.       serIn[0]='0';
  308.     }
  309.     // M => set mail counter
  310.     if (serIn[0]=='M') {
  311.       for (u=1;serIn[u]!=0;u++) {
  312.         mailCounter[u-1]=serIn[u];
  313.       }
  314.       mailCounter[u+1]=0;
  315.     }
  316.    
  317.     // play the tune
  318.     if (mailCounter[0]!='0') {
  319.       for (int note=0; note<3; ++note) {
  320.         tone(10,mailtune[note],75);
  321.         delay(100);
  322.         noTone(10);
  323.         digitalWrite(10, HIGH);
  324.       }
  325.     }
  326.    
  327.    
  328.   }
  329.   // ***End serial comms***
  330. }
  331.  
  332.  
  333. void setup()
  334. {
  335.   Serial.begin(9600);
  336.   lcd.begin(20, 2);
  337.   loadchars();
  338.   for (int note=0; note<4; ++note) {
  339.     tone(10,startuptune[note],75);
  340.     delay(100);
  341.     noTone(10);
  342.   }
  343. }
  344.  
  345. double temp(int pin)
  346. {
  347.   double Temp;
  348.   Temp = log(((10240000/analogRead(pin)) - 10000));
  349.   Temp = 1 / (0.001129148 + (0.000234125 * Temp) + (0.0000000876741 * Temp * Temp * Temp));
  350.   Temp = Temp - 273.15;
  351.  
  352.   return Temp;
  353. }
  354.  
  355. void bigtemp()
  356. {
  357.   bigprint(temp(0),0);
  358.   lcd.setCursor(14,0);
  359.   lcd.write(5);
  360.   printbigchar(10,4,0);
  361. }
  362.  
  363. void loop()
  364. {
  365.   for(int i=0;i<40;i++){
  366.     bigtemp();
  367.     delay(100);
  368.     serial();
  369.   }
  370.   for(int i=0;i<20;i++){
  371.     lcd.scrollDisplayRight();
  372.     delay(50);
  373.   }
  374.  
  375.  
  376.   printbigchar(11,4,0);
  377.   bigclock(0,0,mailCounter);
  378.  
  379.   for(int i=0;i<20;i++){
  380.     lcd.scrollDisplayRight();
  381.     delay(50);
  382.   }
  383.  
  384.   for(int i=0;i<40;i++){
  385.     bigclock(0,0,mailCounter);
  386.     delay(100);
  387.     serial();
  388.   }
  389.  
  390.   for(int i=0;i<20;i++){
  391.     lcd.scrollDisplayRight();
  392.     delay(50);
  393.   }
  394.   printbigchar(11,3,0);
  395.   bigtemp();
  396.   for(int i=0;i<20;i++){
  397.     lcd.scrollDisplayRight();
  398.     delay(50);
  399.   }
  400. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement