Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Amateur Radio Station Clock
- *
- * learnelectronics
- * 13 MAR 2018
- *
- * www.youtube.com/c/learnelectronics
- * email: [email protected]
- */
- #include <DS3231.h> //RTC library
- #include <Wire.h> //i2c library
- #include <Adafruit_GFX.h> // Core graphics library
- #include <Adafruit_TFTLCD.h> // Hardware-specific library
- #define LCD_CS A3 // Chip Select goes to Analog 3
- #define LCD_CD A2 // Command/Data goes to Analog 2
- #define LCD_WR A1 // LCD Write goes to Analog 1
- #define LCD_RD A0 // LCD Read goes to Analog 0
- #define LCD_RESET A4 // LCD reset goes to pin A4
- // Assign names to some common 16-bit color values:
- #define BLACK 0x0000
- #define BLUE 0x001F
- #define RED 0xF800
- #define GREEN 0x07E0
- #define CYAN 0x07FF
- #define MAGENTA 0xF81F
- #define YELLOW 0xFFE0
- #define WHITE 0xFFFF
- //Global variables
- bool Century=false;
- bool h12;
- bool PM;
- byte ADay, AHour, AMinute, ASecond, ABits;
- bool ADy, A12h, Apm;
- byte year, month, date, DoW, hour, minute, second;
- DS3231 Clock;
- Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
- void setup(void) { //Setup Loop
- Serial.begin(9600);
- tft.reset();
- Clock.enableOscillator(1,0,3);
- tft.begin(0x9341);
- Wire.begin();
- delay(500);
- tft.setRotation(1);
- tft.fillScreen(BLACK);
- tft.setCursor(0, 0);
- tft.setTextColor(WHITE);
- tft.setTextSize(2);
- tft.println(" KX1ABC Station Time"); //change for YOUR callsign
- }
- void loop(void) { //Main Loop
- //read clock data
- int second,minute,hour,date,month,year,temperature;
- second=Clock.getSecond();
- minute=Clock.getMinute();
- hour=Clock.getHour(h12, PM);
- date=Clock.getDate();
- month=Clock.getMonth(Century);
- year=Clock.getYear();
- temperature=Clock.getTemperature();
- //display clock data
- tft.setRotation(1);
- tft.fillScreen(BLACK);
- tft.setCursor(0, 0);
- tft.setTextColor(WHITE);
- tft.setTextSize(2);
- tft.println(" KE8IXE Station Time");
- tft.setCursor(0, 40);
- tft.setTextSize(3);
- tft.setTextColor(YELLOW);
- tft.print("Local: ");
- if (hour<10) tft.print("0");
- tft.print(hour,DEC);
- tft.print(':');
- if (minute<10) tft.print("0");
- tft.println(minute,DEC);
- tft.setCursor(0, 80);
- tft.setTextSize(3);
- tft.setTextColor(GREEN);
- tft.print("UTC: ");
- tft.print(hour+4,DEC);
- tft.print(':');
- if (minute<10) tft.print("0");
- tft.println(minute,DEC);
- tft.setCursor(0, 120);
- tft.setTextSize(3);
- tft.setTextColor(BLUE);
- tft.print("Date: ");
- tft.print(month,DEC);
- tft.print('/');
- tft.print(date,DEC);
- tft.print('/');
- tft.print(year,DEC);
- tft.setCursor(0, 160);
- tft.setTextSize(3);
- tft.setTextColor(WHITE);
- tft.print("Temp. ");
- tft.print(temperature);
- tft.print("C ");
- tft.print((temperature*1.8)+32,0);
- tft.print("F ");
- tft.setCursor(0, 200);
- tft.setTextSize(1);
- tft.setTextColor(RED);
- tft.print(" Remember ident every 10 min.");
- delay(30000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement