Advertisement
Guest User

Untitled

a guest
Oct 17th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.83 KB | None | 0 0
  1. #include <Adafruit_LEDBackpack.h>
  2. #include <Adafruit_GFX.h>
  3. #include <TinyGPS++.h>
  4. #include <SoftwareSerial.h>
  5. #include <Wire.h>
  6. #include <Time.h>
  7.  
  8. Adafruit_7segment matrix = Adafruit_7segment();
  9. static const int RXPin = 4, TXPin = 3;
  10. static const uint32_t GPSBaud = 9600;
  11. TinyGPSPlus gps;
  12. SoftwareSerial ss(RXPin, TXPin);
  13. unsigned long last = 0UL;
  14. #define TIMEZONE var1 //UTC offset. +1 hour = BST
  15. const int dstPin = A1;
  16. int var1 = 0;
  17. //
  18. int counter = 0; // how many times we have seen new value
  19. int reading; // the current value read from the input pin
  20. int current_state = LOW; // the debounced input value
  21.  
  22. // the following variable is a long because the time, measured in milliseconds,
  23. // will quickly become a bigger number than can be stored in an int.
  24. long time = 0; // the last time the output pin was sampled
  25. int debounce_count = 10; // number of millis/samples to consider before declaring a debounced input
  26.  
  27.  
  28.  
  29. void setup()
  30. {
  31. Serial.begin(9600);
  32. pinMode(dstPin, INPUT);
  33. ss.begin(GPSBaud);
  34. matrix.begin(0x70);
  35. matrix.clear();
  36. matrix.setBrightness(1); //screenbrightness
  37. }
  38.  
  39.  
  40. void loop()
  41.  
  42. {
  43. //
  44. // If we have gone on to the next millisecond
  45. if(millis() != time)
  46. {
  47. reading = digitalRead(dstPin);
  48.  
  49. if(reading == current_state && counter > 0)
  50. {
  51. counter--;
  52. }
  53. if(reading != current_state)
  54. {
  55. counter++;
  56. }
  57. // If the Input has shown the same value for long enough let's switch it
  58. if(counter >= debounce_count)
  59. {
  60. counter = 0;
  61. current_state = reading;
  62. var1 = current_state;
  63. }
  64. time = millis();
  65. }
  66.  
  67. //
  68. //if (dstPin == HIGH){
  69. //buttonState == 1;
  70. //}
  71. //else
  72. //{
  73. //buttonState == 0;
  74. //}
  75.  
  76. // Receive GPS from Software Serial
  77. while (ss.available() > 0)
  78. gps.encode(ss.read());
  79.  
  80. if (millis() - last > 500)
  81. {
  82.  
  83. if (gps.charsProcessed() < 10)
  84. Serial.println(F("WARNING: No GPS data. Check wiring."));
  85.  
  86. last = millis();
  87. //
  88. if (gps.time.isUpdated() && gps.date.isUpdated()) {
  89. byte Year = gps.date.year();
  90. byte Month = gps.date.month();
  91. byte Day = gps.date.day();
  92. byte Hour = gps.time.hour();
  93. byte Minute = gps.time.minute();
  94. byte Second = gps.time.second();
  95. setTime(Hour, Minute, Second, Day, Month, Year);
  96. adjustTime(TIMEZONE * SECS_PER_HOUR); //Set time to current timezone
  97. //Set the RTC to GPS time.
  98. }
  99. //
  100. //blink
  101. if ((second() % 2) == 0)
  102. {
  103. matrix.writeDigitRaw(2,0x2);
  104. }
  105. else
  106. {
  107. matrix.writeDigitRaw(2,0x0);
  108. }
  109.  
  110. //blink
  111.  
  112. //display code start
  113. matrix.writeDigitNum(0, hour()/10);
  114. matrix.writeDigitNum(1, hour()%10);
  115. matrix.writeDigitNum(3, minute()/10);
  116. matrix.writeDigitNum(4, minute()%10);
  117. matrix.writeDisplay();
  118. //display code end
  119. }
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement