mbed应用板lcd屏幕按钮控制

时间:2016-04-08 18:16:00

标签: c++ button gps lcd mbed

  #include "mbed.h"
  #include "C12832_lcd.h"
  #include<cstring>
  #include<string>
  #include<sstream>

     C12832_LCD lcd;//creating LCD object
     Serial s_comms(USBTX, USBRX);//creating a serial comms object

     DigitalIn Button(p14);//using button to change pages


   int main()

  {

    char str[100] =   "$GPRMC,123519,A,4807.038,N,01131.000,E,022.4,084.4,230394,003.1,W*6A";

char*point;
point = strtok(str, ",");

int page_state = 0;

for (int i = 0; point != NULL; i++){


    //time
    if (i == 1 and page_state == 0){
        //using substrings to extract time elements
        string time = point;
        string hrs = time.substr(0, 2);
        string mins = time.substr(2, 2);
        string sec = time.substr(4, 2);

        //using string streams to reformat time string
        ostringstream tim;
        tim << hrs << ":" << mins << ":" << sec;
        time = tim.str();

        lcd.cls();
        lcd.locate(0, 1);
        lcd.printf("%s\n", time.c_str());

    }

    //date
    if (i == 9 and page_state == 0){
        string date = point;
        string day = date.substr(0, 2);
        string month = date.substr(2, 2);
        string year = date.substr(4, 2);

        //Converting the numerical month into abbreviation ect. 
        if (month == "03"){
            month = "Mar";
        }

        if (month == "04"){
            month = "Apr";
        }

        ostringstream dat;
        dat << day << "-" << month << "-20" << year;
        date = dat.str();

        lcd.locate(0, 9);
        lcd.printf("%s\n", date.c_str());

    }

    //latitude
    if (i == 3 and page_state == 0){
        string lati = point;
        string lati_deg = lati.substr(0, 2);
        string sml_latideg = lati.substr(2, 6);

        ostringstream lat;
        lat << "Lat: " << lati_deg << " deg " << sml_latideg << "'";
        lati = lat.str();

        lcd.locate(0, 18);
        lcd.printf("%s", lati.c_str());
    }


    //latitude direction (N or S)
    if (i == 4 and page_state == 0){
        string lat_dir = point;
        lcd.printf("%s\n", lat_dir.c_str());
        }

     point = strtok(NULL, ",");
    }


    //Change page

    if (Button == 1){
        page_state = !page_state;//toggle page state    
        wait(0.2);//debounce timer
        lcd.cls();
        }


    //second page
    for (int j = 0; point != NULL; j++){

        char str[100]      ="$GPRMC,123519,A,4807.038,N,01131.000,E,022.4,084.4,230394,003.1,W*6A";
         char*point;
        point = strtok(str, ",");
         //longitude
         if (j == 5 and page_state == 1){
          string lngi = point;
          string lngi_deg = lngi.substr(0, 2);
          string sml_lngideg = lngi.substr(2, 6);

         ostringstream lng;
         lng << "Lng: " << lngi_deg << " deg " << sml_lngideg << "'";
         lngi = lng.str();

         lcd.locate(0, 1);
         lcd.printf("%s", lngi.c_str());
         }

        //longitude direction (E or W)
        if (j == 6 and page_state == 1){
        string lng_dir = point;

        lcd.printf("%s\n", lng_dir.c_str());
        }

        //speed
        if (j == 7 and page_state == 1){
        string speed = point;

        ostringstream spd;
        spd << "Speed: " << speed;
        speed = spd.str();

        lcd.locate(0, 9);
        lcd.printf("%s\n", speed.c_str());
        }

        point = strtok(NULL, ",");
        }


    return 0;

}

你好,试图让mbed应用板上的板载按钮允许我清除屏幕并输入新信息,按钮当前什么都不做,我在屏幕上获得前4个部分的信息但是这不是按下按钮时更改,我需要帮助才能尝试这项工作

0 个答案:

没有答案