Hello,
I have a sketch With GPS RTC clock and a Oled This work fine but when I do the #include <Adafruit_Sensor.h> to my sketch it is not working any more what is here the problem, a conflict??
[b]#include <Adafruit_Sensor.h>[/b]
#include <Adafruit_SSD1306.h>
#include <Adafruit_GFX.h>
#include <NMEAGPS.h>
#include <NeoSWSerial.h>
#include <SPI.h>
#include <Wire.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
static const uint32_t GPSBaud = 9600;
NMEAGPS gps;
static const int RXPin = 16, TXPin = 15;
NeoSWSerial gps_port(RXPin, TXPin);
static char* dayName[] = { "ZONDAG", "MAANDAG", "DINSDAG", "WOENSDAG", "DONDERDAG", "VRIJDAG", "ZATERDAG" };
static char* monthName[] = { "JAN", "FEB", "MAA", "APR", "MEI", "JUN", "JUL", "AUG", "SEP", "OKT", "NOV", "DEC" };
static void adjustTime(NeoGPS::time_t& UTCtime);
static void printTime(gps_fix& fix);
void setup() {
gps_port.begin(GPSBaud); //Arduino Serial
Wire.begin();
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3D (for the 128x64 OLED display)
display.setTextSize(0); //Set default font size to the smalles
display.setTextColor(WHITE, BLACK); //Set font to display color on black background
display.dim(0); //Set display to full brightness
display.invertDisplay(0);
display.clearDisplay();
}
void loop() {
while (gps.available(gps_port)) {
gps_fix fix = gps.read();
printTime(fix);
}
}
static void printTime(gps_fix& fix) {
display.drawLine(0, 16, 128, 16, WHITE);
display.setCursor(10, 0);
display.setTextSize(2);
display.setTextColor(WHITE, BLACK);
// Time
if (fix.valid.time) {
adjustTime(fix.dateTime);
if (fix.dateTime.hours < 10) display.print('0');
display.print(fix.dateTime.hours);
display.print(':');
if (fix.dateTime.minutes < 10) display.print('0');
display.print(fix.dateTime.minutes);
display.print(':');
if (fix.dateTime.seconds < 10) display.print('0');
display.print(fix.dateTime.seconds);
}
// Satellites
display.setTextSize(0);
display.setCursor(116, 56);
if (fix.valid.satellites) {
if (fix.satellites < 10) display.print('0');
display.print(fix.satellites);
}
else
display.print("--");
// Date
display.setCursor(0, 19); // display.setCursor(0, 20);
display.setTextSize(0);
display.setTextColor(WHITE, BLACK);
if (fix.valid.date) {
fix.dateTime.set_day(); // set the "day" member from all the adjusted pieces
display.print(dayName[fix.dateTime.day - 1]); // SUNDAY = 1, dayNames array starts at 0.
display.print(' ');
if (fix.dateTime.date < 10) display.print('0');
display.print(fix.dateTime.date);
display.print(' ');
fix.dateTime.set_day(); // set the "day" member from all the adjusted pieces
display.print(monthName[fix.dateTime.month - 1]); // SUNDAY = 1, dayNames array starts at 0.
display.print(' ');
if (fix.dateTime.full_year() < 10) display.print('0');
display.print(fix.dateTime.full_year());
}
display.display();
}
static void adjustTime(NeoGPS::time_t& UTCtime)
{
NeoGPS::clock_t seconds = UTCtime;
// Daylight Savings Time rule (calculated once per reset and year!)
static NeoGPS::time_t changeover;
static NeoGPS::clock_t springForward, fallBack;
if ((springForward == 0) || (changeover.year != UTCtime.year)) {
changeover.year = UTCtime.year;
changeover.month = 3;
changeover.date = 30; // last Sunday
changeover.hours = 2; // am
changeover.minutes = 0;
changeover.seconds = 0;
changeover.set_day();
// Step back to the 4th Sunday, if day != SUNDAY
changeover.date -= (changeover.day - NeoGPS::time_t::SUNDAY);
springForward = (NeoGPS::clock_t) changeover;
changeover.month = 11;
changeover.date = 30; // last Sunday
changeover.hours = 2; // am, adjusted for DST in effect at that time
changeover.set_day();
// Step back to the 4th Sunday, if day != SUNDAY
changeover.date -= (changeover.day - NeoGPS::time_t::SUNDAY);
fallBack = (NeoGPS::clock_t) changeover;
}
// Set these values to the offset of your timezone from GMT
static const int32_t zone_hours = +1L; // CET
static const int32_t zone_minutes = 0L; // zero for CET
static const NeoGPS::clock_t zone_offset =
zone_hours * NeoGPS::SECONDS_PER_HOUR +
zone_minutes * NeoGPS::SECONDS_PER_MINUTE;
seconds += zone_offset; // adjust!
if ((springForward <= seconds) && (seconds < fallBack))
seconds += NeoGPS::SECONDS_PER_HOUR;
UTCtime = seconds; // convert back to a structure