Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Time.h>
- #include <TimeLib.h>
- #include <fontALL.h>
- #include <Wire.h>
- //#include <TinyGPS.h> // http://arduiniana.org/libraries/TinyGPS/
- //#include <SoftwareSerial.h>
- #include <DS1302RTC.h>
- #include <TVout.h>
- time_t prevDisplay = 0; // when the digital clock was displayed
- //const int offset = -5;
- #include <math.h>
- //uint8_t hour12 = hour()%12 == 0? 12 : hour()%12;
- long previousMillis = 0;
- long interval = 900;
- // Init the DS1302
- // Set pins: CE, IO,CLK
- DS1302RTC RTC(2, 3, 4);
- //SoftwareSerial SerialGPS = SoftwareSerial(10, 11); // receive on pin 10
- TVout TV;
- //TinyGPS gps;
- // Optional connection for RTC module
- //#define DS1302_GND_PIN 33
- //#define DS1302_VCC_PIN 35
- // Init the LCD
- // initialize the library with the numbers of the interface pins
- // lcd(RS, E, d4, d5, d6, d7, bl, polarity)
- 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()
- {
- // Setup LCD to 16x2 characters
- TV.begin(_NTSC,138,96);
- TV.select_font(font8x8);
- TV.delay_frame(100);
- // Activate RTC module
- //Serial.begin(115200);
- //while (!Serial) ; // Needed for Leonardo only
- //SerialGPS.begin(9600);
- TV.set_cursor(0, 1);
- Serial.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 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");
- print2digits(hour()%12 == 0? 12 : hour()%12);
- TV.print(":");
- print2digits(minute());
- TV.print(":");
- print2digits(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
- print2digits(day());
- TV.print("/");
- print2digits(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
- print2digits(day());
- TV.print("/");
- print2digits(month());
- TV.print("/");
- TV.print(year());
- }
- //}
- }
- void print2digits(int number) {
- if (number >= 0 && number < 10) {
- TV.write('0');
- }
- TV.print(number);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement