Advertisement
devicemodder

Untitled

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