If statement problem

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]

This expression:

  • if (scroll = 1) {*

is not a test for equality. This is

  • if (scroll == 1) {*

Note the double equal sign.

Please read the post at the top of the Forum on the proper way to post source code here using code tags. Also, you may want to reformat your code in the IDE using Ctrl-T to make it a more standard C format.

Please correct your post above and add code tags around your code:

[code]

[color=blue]// your code is here[/color]

[/code]

.

It should look like this:

// your code is here

(Also press ctrl-T (PC) or cmd-T (Mac) in the IDE before copying to indent your code properly)


Read quickly and would start there: are you sure about this   if (up [color=red]=[/color] HIGH) {

jml I will do that, sorry this is my first post.

Was going to point out the = vs == thing but got scooped.

But also, unless you have external pullups or pulldowns on those buttons you should guarantee their state with pinMode(x, INPUT_PULLUP); and switch the pin to ground. (You didn't say how they're wired)

edit: using a pullup means the pin will be high normally, and go low when the button is pressed

OrigamiBoy:
jml I will do that, sorry this is my first post.

yes that's a poor excuse :slight_smile: (kidding you are not the only one)

Someone smart took the time to write two posts that are anchored at the top of the forum

How to use this forum - please read.
Read this before posting a programming question

You will be forgiven if you fix your first post and go read those ! :slight_smile: (and you'll see that you'll learn plenty as well by doing so)

OrigamiBoy:
I have been trying to fix this problem for around an hour now with no luck.

That is a trivially short amount of time. Spending 2 days on a problem would not be unusual.

...R

I am trying to get a GPS to print its values to a screen.

The GPS is simply NOT designed to do that.

The GPS prints to the screen just fine,

Complete nonsense. The GPS does NOT print "to the screen". The Arduino prints data from the GPS to the serial port.

PaulS:
The GPS is simply NOT designed to do that.
Complete nonsense. The GPS does NOT print "to the screen". The Arduino prints data from the GPS to the serial port.

Just curious, why was this post necessary ? Why do some of you feel as if being rude to the OP is acceptable, i am unsure what a post like this even does, make sure the OP knows he is stupid ?

Main reason i normally do not come to sites like this, people are trying to learn, and most of you are just trying to be offended.

dcosper:
Just curious, why was this post necessary ?

Well you don't get to 80k posts without some effort :wink:

kenwood120s:
Well you don't get to 80k posts without some effort :wink:

Good point, i just read these now to learn, i myself am done asking this group questions lol, i can get treated like crap at home, don't need to add it to my leisure time.

Some teachers can be tough ones but you should not take this personally.

What was written above by Paul is not a value judgement of the person, it's a technical fact, the naked truth.

Engineering requires discipline and structured thinking. Expressing what one desires to do or what is happening in a code is a skill that every aspiring tinkerer, maker or programmer need to learn.

You know the sayings "spare the rod, spoil the child" or "you have to be cruel to be kind"..

So focus on the essential, the learning and not how you perceive the tone of the mail.

You'll see that those who work hard get respect and support from the forum.

J-M-L:
Some teachers can be tough ones but you should not take this personally.

What was written above by Paul is not a value judgement of the person, it's a technical fact, the naked truth.

Engineering requires discipline and structured thinking. Expressing what one desires to do or what is happening in a code is a skill that every aspiring tinkerer, maker or programmer need to learn.

You know the sayings "spare the rod, spoil the child" or "you have to be cruel to be kind"..

So focus on the essential, the learning and not how you perceive the tone of the mail.

You'll see that those who work hard get respect and support from the forum.

Although i feel you have the right to your opinion, i disagree, and allow me to explain why, I am a 49 year old disabled veteran, currently rated at 70% service connection for PTSD, I program because the daemons in my head cannot get through it, i can spend hours and hours effectively shielded from the insanity that is me, and just like anyone else who is learning things, there are many times i need to ask the opinion of a more experienced person in order to comprehend the correct way to code something, when i do so on this site, all i get is BS, and not one fair, or even a wrong solution to try, i post about how to pass a ref to a class correctly and have people complaining about code at the very bottom not yet completed, that has nothing to do with it, now if i had gotten an answer as well as just being an outlet for someones bad day, i could say, oh well, people are crap, but i got an answer to try.

It would be nice to find some other people interested in simply learning, and not being a jackass, really is the one line summation for this, i will get off my soapbox now.

First, thank you for your service.

Second, as a teacher for more years than you've yet seen, I know that it's easy to get a little "crusty" when you've seen the same (or very similar) questions asked many times. (Also, reread Paul's tagline.) Paul's 81K posts verifies he's seen a lot of questions pass through this Forum. That said, the really important statistic is the 2000+ Karma points where posters saw enough worth in what Paul said, regardless of how it was delivered, to rate it noteworthy. As a student who really wants to learn, which would you rather have: A teacher who gives you the equivalent of a Participation Trophy, or a mean SOB who's going to teach you something. Likely you went through basic training with a DI who probably wasn't your best friend, but what he taught you likely help you live through the hell you experienced. It's the same here, only on a much lesser level.

When you come to this Forum, do so with the attitude that some SOB DI is going to run roughshod over your feelings, but you'll come away with a nugget of knowledge that makes the trip worthwhile.

It's too soon in your journey for you to give up on this Forum.

econjack:
come away with a nugget of knowledge that makes the trip worthwhile.

I'm an educator too, and would never disagree with the notion of making learning some kind of challenging experience vs getting an attendance certificate.

But that said, there was no nugget of knowledge in PaulS' reply #7, which is the proximal cause of this discussion. Obviously, the Arduino, not the GPS, was doing the printing, and since the OP had code that was doing that, he knew that. To point out that his statement about the GPS doing the printing was nonsense was unnecessary and serves no purpose what-so-ever. Well, it adds to his post count I suppose, but and maybe this is the important part, it contributes to his measly percentage of karma to posts.

Your (@econjack here) percentage of karma to posts otoh, points to the fact that you don't tell people that buttons belong on shirts.

kenwood120s:
But that said, there was no nugget of knowledge in PaulS' reply #7,...

Agreed, but sometimes it's one of those Wheat-Chaff situations.

kenwood120s:
I'm an educator too, and would never disagree with the notion of making learning some kind of challenging experience vs getting an attendance certificate.

But that said, there was no nugget of knowledge in PaulS' reply #7, which is the proximal cause of this discussion. Obviously, the Arduino, not the GPS, was doing the printing, and since the OP had code that was doing that, he knew that. To point out that his statement about the GPS doing the printing was nonsense was unnecessary and serves no purpose what-so-ever. Well, it adds to his post count I suppose, but and maybe this is the important part, it contributes to his measly percentage of karma to posts.

Your (@econjack here) percentage of karma to posts otoh, points to the fact that you don't tell people that buttons belong on shirts.

This is how i feel about it, with me, and the issues i deal with, a person with a rude reply that gives me no knowledge is to me a person just looking to press peoples buttons, and i press back, never proud of it, just how i work now, no teacher should ever be rude and disrespectful to the student, all they learn from that is their teacher is an ahole, i am a C# guy, i may need to learn how to write my c# ideas into c++ functions but, i have written game emulators in c#, i have written network streams and drivers with c#, if you guys would have given me half a chance i would have learned, instead, after reading so many posts here i now feel as if google and stack exchange will be the better solution, in addition, another frustrating point i have, is, if any new guy were to come here and speak to some of you in the manner you spoke to them, it would be all chaos, people who believe rudeness is the answer, never mean for them, just you.

Sorry to hear about your condition & glad to hear you find comfort in exploring technology.

Technical accuracy is important. that's the message in #7 and Paul seems passionate about it :slight_smile:

I would not take comments so personal. I'd love to hear about the OP's work with the = and == that we mentioned though and what progress he did since