Hi, I have been trying to fix this problem for around an hour now with no luck.
I am trying to get a GPS to print its values to a screen. The GPS prints to the screen just fine, but the screen is too small for it to display all its data. I created a scroll value that changes when the "up" or "down" buttons are pressed. those buttons are hooked up to digital 6 and 7. Everything should work fine, but the if statements are not working, the screen is printing the data that it's supposed to when scroll = 1 even when scroll = 2. Please help
Code:
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
// If using software SPI (the default case):
#define OLED_MOSI 9
#define OLED_CLK 10
#define OLED_DC 11
#define OLED_CS 12
#define OLED_RESET 13
Adafruit_SSD1306 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);
#define NUMFLAKES 10
#define XPOS 0
#define YPOS 1
#define DELTAY 2
#define LOGO16_GLCD_HEIGHT 16
#define LOGO16_GLCD_WIDTH 16
#include <Adafruit_GPS.h>
#include <SoftwareSerial.h>
SoftwareSerial mySerial(3, 2);
Adafruit_GPS GPS(&mySerial);
#define GPSECHO true
// this keeps track of whether we're using the interrupt
// off by default!
boolean usingInterrupt = false;
void useInterrupt(boolean); // Func prototype keeps Arduino 0023 happy
void setup()
{
pinMode(6, INPUT);
pinMode(7, INPUT);
Serial.begin(115200);
Serial.println("Adafruit GPS library basic test!");
// by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
display.begin(SSD1306_SWITCHCAPVCC);
display.display();
// 9600 NMEA is the default baud rate for Adafruit MTK GPS's- some use 4800
GPS.begin(9600);
// uncomment this line to turn on RMC (recommended minimum) and GGA (fix data) including altitude
GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ); // 1 Hz update rate
GPS.sendCommand(PGCMD_ANTENNA);
useInterrupt(true);
delay(100);
// Ask for firmware version
mySerial.println(PMTK_Q_RELEASE);
}
// Interrupt is called once a millisecond, looks for any new GPS data, and stores it
SIGNAL(TIMER0_COMPA_vect) {
char c = GPS.read();
// if you want to debug, this is a good time to do it!
#ifdef UDR0
if (GPSECHO)
if (c) UDR0 = c;
// writing direct to UDR0 is much much faster than Serial.print
// but only one character can be written at a time.
#endif
}
void useInterrupt(boolean v) {
if (v) {
// Timer0 is already used for millis() - we'll just interrupt somewhere
// in the middle and call the "Compare A" function above
OCR0A = 0xAF;
TIMSK0 |= _BV(OCIE0A);
usingInterrupt = true;
} else {
// do not call the interrupt function COMPA anymore
TIMSK0 &= ~_BV(OCIE0A);
usingInterrupt = false;
}
}
uint32_t timer = millis();
void loop() // run over and over again
{
// in case you are not using the interrupt above, you'll
// need to 'hand query' the GPS, not suggested :(
if (! usingInterrupt) {
// read data from the GPS in the 'main loop'
char c = GPS.read();
// if you want to debug, this is a good time to do it!
if (GPSECHO)
if (c) Serial.print(c);
}
// if a sentence is received, we can check the checksum, parse it...
if (GPS.newNMEAreceived()) {
// a tricky thing here is if we print the NMEA sentence, or data
// we end up not listening and catching other sentences!
// so be very wary if using OUTPUT_ALLDATA and trytng to print out data
//Serial.println(GPS.lastNMEA()); // this also sets the newNMEAreceived() flag to false
if (!GPS.parse(GPS.lastNMEA())) // this also sets the newNMEAreceived() flag to false
return; // we can fail to parse a sentence in which case we should just wait for another
}
// if millis() or timer wraps around, we'll just reset it
if (timer > millis()) timer = millis();
// approximately every 2 seconds or so, print out the current stats
//if (millis() - timer > 2000) {
//timer = millis(); // reset the timer
int up = digitalRead(6);
int down = digitalRead(7);
int scroll = 1;
if (up = HIGH) {
scroll++;
}
else if (down > HIGH) {
scroll--;
}
//scroll = 2;
display.setTextSize(.5);
display.setTextColor(WHITE);
display.setCursor(2,0);
display.clearDisplay();
display.println();
if (scroll = 1) {
display.print("\nTime: ");
display.print(GPS.hour, DEC); display.print(':');
display.print(GPS.minute, DEC); display.print(':');
display.print(GPS.seconds, DEC); display.print('.');
display.println(GPS.milliseconds);
display.print("Date: ");
display.print(GPS.day, DEC); display.print('/');
display.print(GPS.month, DEC); display.print("/20");
display.println(GPS.year, DEC);
}
//scroll = 2;
if (scroll = 2); {
display.print("Date: ");
display.print(GPS.day, DEC); display.print('/');
display.print(GPS.month, DEC); display.print("/20");
display.println(GPS.year, DEC);
display.print("Fix: "); display.print((int)GPS.fix);
display.print(" quality: "); display.println((int)GPS.fixquality);
display.display();
;}
if (GPS.fix) {
display.print("Location: ");
display.print(GPS.latitude, 4); display.print(GPS.lat);
display.print(", ");
display.print(GPS.longitude, 4); display.println(GPS.lon);
display.print("Location (in degrees, works with Google Maps): ");
display.print(GPS.latitudeDegrees, 4);
display.print(", ");
display.println(GPS.longitudeDegrees, 4);
display.print("Speed (knots): "); display.println(GPS.speed);
display.print("Angle: "); display.println(GPS.angle);
display.print("Altitude: "); display.println(GPS.altitude);
display.print("Satellites: "); display.println((int)GPS.satellites);
}
delay(200);
//}
}
[code]
[/code]