Ardunio GPS waypoints switch case statement

hello everyone, I am having problems using the switch case statements on my code… I don’t really understand how it works… please help!

float currentDegrees;


float refill_latitude = 12.9 ;
float refill_longitude = -12.0 ;
float dest_latitude; // waypoint 2
float dest_longitude;
float dest_latitude1 = 12.335658; // waypoint 1
float dest_longitude1 = -12.520629;
float dest_latitude2 = 12.335478; // waypoint 2
float dest_longitude2 = -12.523761;
float dest_latitude3 = 12.335658; // waypoint 3
float dest_longitude3 = -12.520629; 
//float latitude, longitude; // current location
//update 11/18/14: change the motor pin 4 to 9, since it is rendering the gps useless which was the main problem.
float myString[20];
 float myString1[20];
 byte index = 0;
 byte index1 = 0;

/* the water sensors will be placed on an analog pin, search " how to make the analog pin into
 digital pin on arduino"
 */
int waterTopSensor = 11; //on analog pin 0
int waterBottomSensor = 12; //on analog pin 1
int motorPinfwd1 = 10;
int motorPinbwd1 = 9;
int motorPinfwd = 5;
int motorPinbwd = 6;
int motorPintop = 7;
int motorPindown = 8;
//int anchorPinup = 11;
//int anchorPindown = 12;
//int batteryPin = 3;
//int val = 1;
//int val1 = 17;
// (0) (1) (2) 3 4 5 6 7 8 9 10 11 12 13 ()= open
void setup(){
  vw_set_ptt_inverted(true);
  vw_set_tx_pin(13);
  vw_setup(4000); // start transmitter
  pinMode(12, INPUT);
  pinMode(11, INPUT);
  // pin 13 is for transmitter
 // pinMode(12, OUTPUT);
 // pinMode(11, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(5, OUTPUT);
 // pinMode(val, OUTPUT);
 // pinMode(val1, OUTPUT);
  //pin 4 is for GPS
  //pinMode(3, INPUT);
  Serial.begin(115200); //start serial
  gpsW.begin(9600); // start gps
  pixy.init(); // start pixy
}

void loop(){  
        gpsWaypoints();
       
}
void gpsWaypoints(){
       int waypoints;
       char a;
       int buttonState1 = digitalRead(waterBottomSensor);
  if (gpsW.available() > 0) {
       char c = gpsW.read();
   if (gps.decode(c)) {
      if (gps.gprmc_status() == 'A') {
        //if(gps.gprmc_distance_to(dest_latitude1, dest_longitude1, MTR)  < 20){
          if(buttonState1 == HIGH){
          waypoints = 'B';
          a = 'B';
          Serial.println(waypoints);
        }
        //}
        if(gps.gprmc_distance_to(dest_latitude2, dest_longitude2, MTR) > 15 && (a == 'B')){
          waypoints = 'C';
          a = 'C';
        }
        if(gps.gprmc_distance_to(dest_latitude3, dest_longitude3, MTR) > 15 && (a == 'C')){
          waypoints = 'D';
          a = 'D';
        }
        if(gps.gprmc_distance_to(dest_latitude1, dest_longitude1, MTR) > 15 && (a == 'D')){
          waypoints = 'B';
        a = 'B';
        }
switch(waypoints){
  case 'B':
      dest_latitude = 12.335658; // waypoint 1
      dest_longitude = -12.520629;
  break;
  case 'C':
        dest_latitude = 12.335478; // waypoint 2
        dest_longitude = -12.523761;
  break;
  case 'D':
 dest_latitude = 12.335658; // waypoint 3
 dest_longitude = -12.520629; 
  break;
}
d = gps.gprmc_course_to(dest_latitude, dest_longitude) - gps.gprmc_course();
        currentDegrees = gps.gprmc_course();
         Serial.print("waypoint 1 degrees from loc:"); Serial.println(d);
         Serial.print("current course in degrees:"); Serial.println(currentDegrees);  
         
      if (d < 0) { d += 360; }
        if (d > 180) { d -= 360; }
        if (d < 5) {
          turnLeft();
        } 
        else if (d > -5) {
          turnRight();
        } else {
          forward();
        }
}
}
}
}

the switch case statement doesnt seem to work, when i run the serial monitor and added a default = 0 for lat and lon, i get a course towards 0 degrees lat and 0 degrees lon.

and i tried

dest_latitude = '\0';
dest_longitude = '\0';

and i still get a course to 0 deg. lat, lon.

The code you posted doesn't compile, so it's hard to go further. Supply the code that you were able to compile, reformat it (Ctrl-T) and then post all of the code.

Why can't you use Tiny Gps library for arduino . Where you can parse data easily . it not even consume much space.

Why can't you use Tiny Gps library for arduino . Where you can parse data easily . it not even consume much space.

The Tiny GPS doesnt have the course as well as distance to while the NMEA does.

heres the remaining code

void turnNW(){
  
}
void turnNE(){
}
void turnSW(){
}
void turnSE(){
}
void fullStop(){
}
   void forward(){
  digitalWrite(10, HIGH);
  digitalWrite(9, LOW);
  digitalWrite(5, HIGH);
  digitalWrite(6, LOW);
}

void backward(){//put motor code here
  digitalWrite(10, LOW);
  digitalWrite(9, HIGH);
  digitalWrite(5, LOW);
  digitalWrite(6, HIGH); // pin 6 will be the backward for the drive motor
}
void turnLeft(){// put motor code here
digitalWrite(10, HIGH);
digitalWrite(9, LOW);
digitalWrite(5, LOW);
digitalWrite(6, HIGH);
}
void turnRight(){// put motor code here
digitalWrite(10, LOW);
digitalWrite(9, HIGH);
digitalWrite(5, HIGH);
digitalWrite(6, LOW);
}

http://arduiniana.org/libraries/tinygpsplus/

Havent you check updated library. which gives course & distance.

float myString[20];
 float myString1[20];

WTF? These names are not something the sharpest crayon in the box would have come up with.

        gpsWaypoints();

A function does something with something. A good name uses a verb to describe what it does, and a noun to describe what it does it with. The verb is missing from this name, so it is impossible to determine what this function does. myFunThatDoesSomething() is about as useful a name.

          a = 'B';

Well, that's perfectly obvious. Not!

and i tried
Code: [Select]


dest_latitude = '\0';
dest_longitude = '\0';



and i still get a course to 0 deg. lat, lon.

Why would you assign NULL to a float?

It really isn't clear what your problem is.