daily pastebin goal
76%
SHARE
TWEET

TweetBox

bobbinz Oct 7th, 2011 (edited) 121 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //TweetBox
  2. //Adam Robbins 2011
  3. //bobbinz.co.uk
  4.  
  5. #include <WProgram.h>
  6. #include <Wire.h>
  7. #include <MAX7456.h>
  8. #include <DS1307.h>
  9. MAX7456 osd;
  10.  
  11. #define DEGREE 127  // degree symbol
  12.  
  13. int ledPin =  8;
  14. int los = 7;
  15.  
  16. void setup()
  17. {
  18.   pinMode(ledPin, OUTPUT);
  19.   digitalWrite(ledPin, HIGH);
  20.   Serial.begin(4800);
  21.   char onebuffer[60];  
  22.   char twobuffer[60];  
  23.   char threebuffer[60];  
  24.   char fourbuffer[60];  
  25.   char fivebuffer[60];  
  26.   char sixbuffer[60];
  27.   osd.begin();
  28.   osd.clear();
  29.   (void) sprintf(onebuffer,"%c%c",0x88,0x89);  
  30.   (void) sprintf(twobuffer,"%c%c%c%c%c%c%c%c%c%c",0x8A,0x8B,0x8C,0x8D,0x8E,0x8F,0x90,0x91,0x92,0x93);  
  31.   (void) sprintf(threebuffer,"%c%c%c%c%c%c%c%c",0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0x9B);  
  32.   (void) sprintf(fourbuffer,"%c%c%c%c%c%c",0xA0,0xA1,0xA2,0xA3,0xA4,0xA5);  
  33.   (void) sprintf(fivebuffer,"%c%c%c%c",0xAC,0xAD,0xAE,0xAF);  
  34.   (void) sprintf(sixbuffer,"%c%c%c%c",0xB6,0xB7,0xB8,0xB9);
  35.   osd.write_to_screen("TweetBox",11,2);
  36.   osd.write_to_screen(onebuffer,18,4);  
  37.   osd.write_to_screen(twobuffer,10,5);  
  38.   osd.write_to_screen(threebuffer,10,6);  
  39.   osd.write_to_screen(fourbuffer,12,7);  
  40.   osd.write_to_screen(fivebuffer,14,8);
  41.   osd.write_to_screen(sixbuffer,14,9);
  42.   osd.write_to_screen("Adam Robbins 2011",6,12);
  43.   osd.write_to_screen("bobbinz.co.uk",8,13,0,1);
  44.   delay(7000);
  45.   digitalWrite(ledPin, LOW);
  46. }
  47.  
  48. void loop()
  49. {
  50.   pinMode(los, INPUT);
  51.   pinMode(ledPin, OUTPUT);
  52.   digitalWrite(los, HIGH);
  53.   int s0;
  54.   int lost;
  55.   int hour;
  56.   char cbuffer[60];
  57.   char fbuffer[60];
  58.   char tbuffer[60];
  59.   char dbuffer[60];
  60.   if(Serial.available())
  61.   {
  62.     digitalWrite(ledPin, HIGH);
  63.     delay(100);
  64.     s0 = Serial.read();
  65.     if (s0 == 255)
  66.     {
  67.       int s1, s2;
  68.       s1 = Serial.read();
  69.       s2 = Serial.read();
  70.       osd.clear();
  71.       if (s1 == 254)   //humidalert
  72.       {
  73.         osd.clear();
  74.         osd.write_to_screen("High Humidity!",12,1);
  75.       }
  76.       else
  77.       {
  78.         int tempMsb, tempLsb;
  79.         float convert;
  80.         int cl, ch;
  81.         tempMsb = (s1 << 4) + (s2 >> 4);    // 12 bit value, after decimal point in lower 4 bits
  82.         tempLsb = s2 & 0x0F;
  83.         if (s1 > 7) // 8 bit negative, convert to 16 bit negative
  84.         {
  85.           tempMsb &= 0xFF;   // mask shifted negative bits
  86.           tempMsb = tempMsb - 256;
  87.           (void) sprintf(cbuffer,"%3d%cC",tempMsb,DEGREE);
  88.           (void) sprintf(fbuffer,"It's Cold!");
  89.         }
  90.         else
  91.         {    
  92.           convert = (tempMsb + (tempLsb/100)) * 1.8 + 32;
  93.           ch = int(convert);
  94.           cl = abs((convert) - ch) * 100;        
  95.           (void) sprintf(cbuffer,"%3d.%02d%cC",tempMsb,tempLsb,DEGREE);
  96.           (void) sprintf(fbuffer,"%3d.%02d%cF",ch,cl,DEGREE);    
  97.         }
  98.       }    
  99.       osd.write_to_screen(cbuffer,1,1);
  100.       osd.write_to_screen(fbuffer,1,2);
  101.       digitalWrite(ledPin, LOW);      
  102.       Serial.flush();      
  103.     }
  104.   }    
  105.   else
  106.   {
  107.     osd.clear();
  108.     osd.write_to_screen("No Data Connection",6,1,0,0);
  109.   }
  110.   lost = digitalRead(los);
  111.   if (lost == 1)
  112.   {    
  113.     osd.write_to_screen("No Video Input",2,14);
  114.   }
  115.   (void) sprintf(tbuffer,"%02i %02i",RTC.get(DS1307_HR,true),RTC.get(DS1307_MIN,false));
  116.   osd.write_to_screen(tbuffer,23,13);  
  117.   (void) sprintf(dbuffer,"%02i/%02i/%04i",RTC.get(DS1307_DATE,false),RTC.get(DS1307_MTH,false),RTC.get(DS1307_YR,false));
  118.   osd.write_to_screen(dbuffer,18,14);
  119.   delay(1000);
  120.   hour = RTC.get(DS1307_HR,false);
  121.   osd.write_to_screen(":",25,13);
  122.   delay(1000);
  123. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top