Advertisement
devicemodder

Untitled

Nov 17th, 2018
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.15 KB | None | 0 0
  1. #include <Time.h>
  2. #include <TimeLib.h>
  3.  
  4.  
  5.  
  6. #include <fontALL.h>
  7.  
  8. #include <Wire.h>
  9. //#include <TinyGPS.h> // http://arduiniana.org/libraries/TinyGPS/
  10. //#include <SoftwareSerial.h>
  11. #include <DS1302RTC.h>
  12.  
  13.  
  14.  
  15.  
  16. #include <TVout.h>
  17. time_t prevDisplay = 0; // when the digital clock was displayed
  18. //const int offset = -5;
  19. #include <math.h>
  20. //uint8_t hour12 = hour()%12 == 0? 12 : hour()%12;
  21.  
  22. long previousMillis = 0;
  23. long interval = 900;
  24. // Init the DS1302
  25. // Set pins: CE, IO,CLK
  26. DS1302RTC RTC(2, 3, 4);
  27. //SoftwareSerial SerialGPS = SoftwareSerial(10, 11); // receive on pin 10
  28. TVout TV;
  29. //TinyGPS gps;
  30. // Optional connection for RTC module
  31. //#define DS1302_GND_PIN 33
  32. //#define DS1302_VCC_PIN 35
  33.  
  34. // Init the LCD
  35. // initialize the library with the numbers of the interface pins
  36. // lcd(RS, E, d4, d5, d6, d7, bl, polarity)
  37.  
  38. double Thermister(int RawADC) {
  39. double Temp;
  40. Temp = log(((10240000/RawADC) - 10000));
  41. Temp = 1 / (0.001129148 + (0.000234125 * Temp) + (0.0000000876741 * Temp * Temp * Temp));
  42. Temp = Temp - 273.15; // Convert Kelvin to Celcius
  43.  
  44. return Temp;
  45. }
  46. void setup()
  47. {
  48. // Setup LCD to 16x2 characters
  49. TV.begin(_NTSC,138,96);
  50. TV.select_font(font8x8);
  51. TV.delay_frame(100);
  52. // Activate RTC module
  53.  
  54. //Serial.begin(115200);
  55. //while (!Serial) ; // Needed for Leonardo only
  56. //SerialGPS.begin(9600);
  57. TV.set_cursor(0, 1);
  58.  
  59. Serial.println("Waiting for GPS time ... ");
  60. }
  61.  
  62.  
  63. void loop()
  64. {
  65. //while (SerialGPS.available()) {
  66. //if (gps.encode(SerialGPS.read())) { // process gps messages
  67. // when TinyGPS reports new data...
  68. // unsigned long age;
  69. // int Year;
  70. // byte Month, Day, Hour, Minute, Second;
  71. // gps.crack_datetime(&Year, &Month, &Day, &Hour, &Minute, &Second, NULL, &age);
  72. //if (age < 500) {
  73. // set the Time to the latest GPS reading
  74. //setTime(Hour, Minute, Second, Day, Month, Year);
  75. // adjustTime(offset * SECS_PER_HOUR);
  76. // }
  77. //}
  78. // }
  79.  
  80. //if (timeStatus()!= timeNotSet) {
  81. // if (now() != prevDisplay) { //update the display only if the time has changed
  82. // prevDisplay = now();
  83. //digitalClockDisplay();
  84. // }
  85. //}
  86.  
  87. //}
  88. // void digitalClockDisplay(){
  89. static int sday = 0; // Saved day number for change check
  90.  
  91. // Display time centered on the upper line
  92. TV.set_cursor(0, 0);
  93. TV.print("Current Time:\n");
  94. print2digits(hour()%12 == 0? 12 : hour()%12);
  95. TV.print(":");
  96. print2digits(minute());
  97. TV.print(":");
  98. print2digits(second());
  99. if (hour() > 11) {
  100.  
  101. TV.print(" PM");
  102. }
  103. else {
  104. TV.print(" AM");
  105. }
  106.  
  107.  
  108.  
  109. // Update in 00:00:00 hour only
  110. if(sday != day()) {
  111. TV.set_cursor(0, 30);
  112. TV.print("Today's Date is:\n");
  113.  
  114. // Display date in the lower right corner
  115. print2digits(day());
  116. TV.print("/");
  117. print2digits(month());
  118. TV.print("/");
  119. TV.print(year());
  120.  
  121.  
  122.  
  123.  
  124. }
  125. // Warning!
  126.  
  127.  
  128. // Save day number
  129. sday = day();
  130.  
  131.  
  132. TV.set_cursor(0, 60);
  133. TV.print("Current Temp: \n");
  134. TV.print(int(Thermister(analogRead(0)))); // display Fahrenheit
  135. TV.print(" Celsius");
  136. // Wait small time before repeating :)
  137. TV.delay_frame(50);
  138. delay(60);
  139.  
  140.  
  141. if ((minute() == 0) && (second() == 0)) {
  142. TV.clear_screen();\
  143. delay(100);
  144. }
  145. else if ((minute() == 30) && (second() == 0)) {
  146.  
  147. //this will be called a dozen times in that 1 second that this function
  148. //is true if I don't put a timer in here to limit how many times it's called
  149.  
  150. // unsigned long currentMillis = millis();
  151.  
  152. //if (currentMillis - previousMillis > interval) { //only true for 100ms based on 900ms interval
  153. //previousMillis = currentMillis;
  154.  
  155. TV.clear_screen();\
  156. delay(100);
  157. }
  158. else{
  159. TV.set_cursor(0, 30);
  160. TV.print("Today's Date is:\n");
  161.  
  162. // Display date in the lower right corner
  163. print2digits(day());
  164. TV.print("/");
  165. print2digits(month());
  166. TV.print("/");
  167. TV.print(year());
  168.  
  169. }
  170.  
  171. //}
  172. }
  173.  
  174.  
  175.  
  176.  
  177. void print2digits(int number) {
  178. if (number >= 0 && number < 10) {
  179. TV.write('0');
  180. }
  181. TV.print(number);
  182. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement