Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Adafruit_LEDBackpack.h>
- #include <Adafruit_GFX.h>
- #include <TinyGPS++.h>
- #include <SoftwareSerial.h>
- #include <Wire.h>
- #include <Time.h>
- Adafruit_7segment matrix = Adafruit_7segment();
- static const int RXPin = 4, TXPin = 3;
- static const uint32_t GPSBaud = 9600;
- TinyGPSPlus gps;
- SoftwareSerial ss(RXPin, TXPin);
- unsigned long last = 0UL;
- #define TIMEZONE var1 //UTC offset. +1 hour = BST
- const int dstPin = A1;
- int var1 = 0;
- //
- int counter = 0; // how many times we have seen new value
- int reading; // the current value read from the input pin
- int current_state = LOW; // the debounced input value
- // the following variable is a long because the time, measured in milliseconds,
- // will quickly become a bigger number than can be stored in an int.
- long time = 0; // the last time the output pin was sampled
- int debounce_count = 10; // number of millis/samples to consider before declaring a debounced input
- void setup()
- {
- Serial.begin(9600);
- pinMode(dstPin, INPUT);
- ss.begin(GPSBaud);
- matrix.begin(0x70);
- matrix.clear();
- matrix.setBrightness(1); //screenbrightness
- }
- void loop()
- {
- //
- // If we have gone on to the next millisecond
- if(millis() != time)
- {
- reading = digitalRead(dstPin);
- if(reading == current_state && counter > 0)
- {
- counter--;
- }
- if(reading != current_state)
- {
- counter++;
- }
- // If the Input has shown the same value for long enough let's switch it
- if(counter >= debounce_count)
- {
- counter = 0;
- current_state = reading;
- var1 = current_state;
- }
- time = millis();
- }
- //
- //if (dstPin == HIGH){
- //buttonState == 1;
- //}
- //else
- //{
- //buttonState == 0;
- //}
- // Receive GPS from Software Serial
- while (ss.available() > 0)
- gps.encode(ss.read());
- if (millis() - last > 500)
- {
- if (gps.charsProcessed() < 10)
- Serial.println(F("WARNING: No GPS data. Check wiring."));
- last = millis();
- //
- if (gps.time.isUpdated() && gps.date.isUpdated()) {
- byte Year = gps.date.year();
- byte Month = gps.date.month();
- byte Day = gps.date.day();
- byte Hour = gps.time.hour();
- byte Minute = gps.time.minute();
- byte Second = gps.time.second();
- setTime(Hour, Minute, Second, Day, Month, Year);
- adjustTime(TIMEZONE * SECS_PER_HOUR); //Set time to current timezone
- //Set the RTC to GPS time.
- }
- //
- //blink
- if ((second() % 2) == 0)
- {
- matrix.writeDigitRaw(2,0x2);
- }
- else
- {
- matrix.writeDigitRaw(2,0x0);
- }
- //blink
- //display code start
- matrix.writeDigitNum(0, hour()/10);
- matrix.writeDigitNum(1, hour()%10);
- matrix.writeDigitNum(3, minute()/10);
- matrix.writeDigitNum(4, minute()%10);
- matrix.writeDisplay();
- //display code end
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement