Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <TVout.h>
- #include <video_gen.h>
- #include <TinyGPS.h>
- #include <TimeLib.h>
- #include <fontALL.h>
- #include <math.h>
- #include <SoftwareSerial.h>
- const int offset = -5;
- //uint8_t hour12 = hour()%12 == 0? 12 : hour()%12;
- long previousMillis = 0;
- long interval = 900;
- SoftwareSerial SerialGPS = SoftwareSerial(4, 3); // receive on pin 4
- TVout TV;
- TinyGPS gps;
- time_t prevDisplay = 0; //this section iks converting thermister temp to celcius
- double Thermister(int RawADC) {
- double Temp;
- Temp = log(((10240000/RawADC) - 10000));
- Temp = 1 / (0.001129148 + (0.000234125 * Temp) + (0.0000000876741 * Temp * Temp * Temp));
- Temp = Temp - 273.15; // Convert Kelvin to Celcius
- return Temp;
- }
- void setup()
- {
- Serial.begin(115200);
- while (!Serial) ; // Needed for Leonardo only
- SerialGPS.begin(9600);
- // Setup LCD to 16x2 characters
- TV.begin(_NTSC,138,96);
- TV.select_font(font8x8);
- TV.delay_frame(100);
- // Activate RTC module
- TV.set_cursor(0, 1);
- TV.println("Waiting for GPS time ... ");
- }
- void loop()
- {
- while (SerialGPS.available()) {
- if (gps.encode(SerialGPS.read())) { // process gps messages
- //when TinyGPS reports new data...
- unsigned long age;
- int Year;
- byte Month, Day, Hour, Minute, Second;
- gps.crack_datetime(&Year, &Month, &Day, &Hour, &Minute, &Second, NULL, &age);
- if (age < 500) {
- //set the Time to the latest GPS reading
- setTime(Hour, Minute, Second, Day, Month, Year);
- adjustTime(offset * SECS_PER_HOUR);
- }
- }
- }
- if (timeStatus()!= timeNotSet) {
- if (now() != prevDisplay) { //update the display only if the time has changed
- prevDisplay = now();
- digitalClockDisplay();
- }
- }
- }
- void printDigits(int digits) {
- //if (digits >= 0 && digits < 10) {
- //TV.write('0');
- //}
- //TV.print(digits);
- TV.print(":");
- if(digits < 10)
- TV.print('0');
- TV.print(digits);
- }
- void digitalClockDisplay(){
- static int sday = 0; // Saved day number for change check
- // Display time centered on the upper line
- TV.set_cursor(0, 0);
- TV.print("Current Time:\n");
- TV.print(hour()%12 == 0? 12 : hour()%12);
- printDigits(minute());
- printDigits(second());
- if (hour() > 11) {
- TV.print(" PM");
- }
- else {
- TV.print(" AM");
- }
- // Update in 00:00:00 hour only
- //if(sday != day()) {
- //*/
- TV.set_cursor(0, 30);
- TV.print("Today's Date is:\n");
- // Display date in the lower right corner
- TV.print(day());
- TV.print("/");
- TV.print(month());
- TV.print("/");
- TV.print(year());
- //}
- // Warning!
- // Save day number
- sday = day();
- TV.set_cursor(0, 60);
- TV.print("Current Temp: \n");
- TV.print(int(Thermister(analogRead(0)))); // display Fahrenheit
- TV.print(" Celsius");
- // Wait small time before repeating :)
- TV.delay_frame(50);
- delay(60);
- if ((minute() == 0) && (second() == 0)) {
- TV.clear_screen();\
- delay(100);
- }
- else if ((minute() == 30) && (second() == 0)) {
- //this will be called a dozen times in that 1 second that this function
- //is true if I don't put a timer in here to limit how many times it's called
- // unsigned long currentMillis = millis();
- //if (currentMillis - previousMillis > interval) { //only true for 100ms based on 900ms interval
- //previousMillis = currentMillis;
- TV.clear_screen();\
- delay(100);
- }
- else{
- TV.set_cursor(0, 30);
- TV.print("Today's Date is:\n");
- // Display date in the lower right corner
- TV.print(day());
- TV.print("/");
- TV.print(month());
- TV.print("/");
- TV.print(year());
- }
- //}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement