Advertisement
learnelectronics

Amateur Radio Station Clock

Mar 14th, 2018
628
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.55 KB | None | 0 0
  1. /*
  2.  * Amateur Radio Station Clock
  3.  *
  4.  * learnelectronics
  5.  * 13 MAR 2018
  6.  *
  7.  * www.youtube.com/c/learnelectronics
  8.  */
  9.  
  10.  
  11.  
  12.  
  13.  
  14. #include <DS3231.h>                                 //RTC library
  15. #include <Wire.h>                                   //i2c library
  16. #include <Adafruit_GFX.h>                           // Core graphics library
  17. #include <Adafruit_TFTLCD.h>                        // Hardware-specific library
  18.  
  19.  
  20. #define LCD_CS A3                                   // Chip Select goes to Analog 3
  21. #define LCD_CD A2                                   // Command/Data goes to Analog 2
  22. #define LCD_WR A1                                   // LCD Write goes to Analog 1
  23. #define LCD_RD A0                                   // LCD Read goes to Analog 0
  24. #define LCD_RESET A4                                // LCD reset goes to pin A4
  25.  
  26.  
  27.                                                     // Assign names to some common 16-bit color values:
  28. #define BLACK   0x0000
  29. #define BLUE    0x001F
  30. #define RED     0xF800
  31. #define GREEN   0x07E0
  32. #define CYAN    0x07FF
  33. #define MAGENTA 0xF81F
  34. #define YELLOW  0xFFE0
  35. #define WHITE   0xFFFF
  36.  
  37.                                                     //Global variables
  38. bool Century=false;
  39. bool h12;
  40. bool PM;
  41. byte ADay, AHour, AMinute, ASecond, ABits;
  42. bool ADy, A12h, Apm;  
  43. byte year, month, date, DoW, hour, minute, second;  
  44. DS3231 Clock;
  45. Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
  46.  
  47.  
  48. void setup(void) {                                  //Setup Loop
  49.   Serial.begin(9600);                            
  50.   tft.reset();
  51.   Clock.enableOscillator(1,0,3);
  52.   tft.begin(0x9341);
  53.   Wire.begin();
  54.   delay(500);
  55.   tft.setRotation(1);
  56.   tft.fillScreen(BLACK);
  57.   tft.setCursor(0, 0);
  58.   tft.setTextColor(WHITE);
  59.   tft.setTextSize(2);
  60.   tft.println("   KX1ABC Station Time");            //change for YOUR callsign
  61.  
  62. }
  63.  
  64. void loop(void) {                                   //Main Loop
  65.  
  66.                                                     //read clock data
  67.   int second,minute,hour,date,month,year,temperature;
  68.   second=Clock.getSecond();
  69.   minute=Clock.getMinute();
  70.   hour=Clock.getHour(h12, PM);
  71.   date=Clock.getDate();
  72.   month=Clock.getMonth(Century);
  73.   year=Clock.getYear();
  74.   temperature=Clock.getTemperature();
  75.  
  76.                                                     //display clock data
  77.   tft.setRotation(1);
  78.   tft.fillScreen(BLACK);
  79.   tft.setCursor(0, 0);
  80.   tft.setTextColor(WHITE);
  81.   tft.setTextSize(2);
  82.   tft.println("   KE8IXE Station Time");
  83.   tft.setCursor(0, 40);
  84.   tft.setTextSize(3);
  85.   tft.setTextColor(YELLOW);
  86.   tft.print("Local:     ");
  87.   if (hour<10) tft.print("0");
  88.   tft.print(hour,DEC);
  89.   tft.print(':');
  90.   if (minute<10) tft.print("0");
  91.   tft.println(minute,DEC);
  92.  
  93.   tft.setCursor(0, 80);
  94.   tft.setTextSize(3);
  95.   tft.setTextColor(GREEN);
  96.   tft.print("UTC:       ");
  97.   tft.print(hour+4,DEC);
  98.   tft.print(':');
  99.   if (minute<10) tft.print("0");
  100.   tft.println(minute,DEC);
  101.  
  102.   tft.setCursor(0, 120);
  103.   tft.setTextSize(3);
  104.   tft.setTextColor(BLUE);
  105.   tft.print("Date:    ");
  106.   tft.print(month,DEC);
  107.   tft.print('/');
  108.   tft.print(date,DEC);
  109.   tft.print('/');
  110.   tft.print(year,DEC);
  111.  
  112.   tft.setCursor(0, 160);
  113.   tft.setTextSize(3);
  114.   tft.setTextColor(WHITE);
  115.   tft.print("Temp.    ");
  116.   tft.print(temperature);
  117.   tft.print("C ");
  118.   tft.print((temperature*1.8)+32,0);
  119.   tft.print("F ");
  120.  
  121.   tft.setCursor(0, 200);
  122.   tft.setTextSize(1);
  123.   tft.setTextColor(RED);
  124.   tft.print("         Remember ident every 10 min.");
  125.  
  126.  
  127.  
  128. delay(30000);
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement