极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 5320|回复: 0

ARDIUNO TFT显示屏 库 错误

[复制链接]
发表于 2017-7-7 18:35:19 | 显示全部楼层 |阅读模式
      

[kenrobot_code]//TFT SDA -> UNO 11
//TFT SCK -> UNO 13
#define TFT_CS  10  // Chip select line for TFT display
#define TFT_A0   9  // Data/command line for TFT
#define TFT_RST  8  // Reset line for TFT (or connect to +5V)
#define TFT_LED  A0
#define SD_CS    4  // Chip select line for SD card
//SD MISO -> UNO 12
//SD SCK -> UNO 13
//SD MOSI -> UNO 11

//GPS tx - UNO rx
//GPS rx - UNO tx

#define BTNZOOMIN 2
#define BTNZOOMOUT 3

#include <Adafruit_GFX.h>    // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library
#include <SPI.h>
#include <TinyGPS.h>
//#include <SD.h>
#include <SdFat.h>

#define _GPS_MPS_PER_KNOT 0.51444444
#define MAP_WIDTH 128
#define MAP_HEIGH 128
#define AjustLon 0.00517
#define AjustLat -0.00266

uint8_t level = 17;
boolean isLED_ON;
boolean hadGPS = false;
uint16_t lightOnCout =0;
#define LEDTIME 60000  // ms
#define TIMEZONE 8
#define DELAYTIME 200  //ms

//movingaverage
#define MOVINGAVERAGECOUT 5
float lats[MOVINGAVERAGECOUT],lons[MOVINGAVERAGECOUT];
uint8_t arrNewPoint = 0;

Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_A0, TFT_RST);
SdFat sd;
SdFile myFile;
TinyGPS gps;
char APPROOT[] ="SMARTGPS/MAP/";
char TRACK[]="SMARTGPS/TRACK";
#define CHECKHOLDTIME 1000
bool isRec = false;

#include "myTileSystem.h"
#include "gpsT.h"
#include "maps.h"

void setup(void) {
  Serial.begin(9600);

  initButtons();
  initArray();

  initTFTLED();

  tft.initR(INITR_BLACKTAB);
  tft.fillScreen(ST7735_BLACK); // Clear display

  //SPI_FULL_SPEED SPI_HALF_SPEED
  if (!sd.begin(SD_CS,SPI_HALF_SPEED))
  {
    tft.setCursor(16, 32);
    tft.setTextColor(ST7735_RED);
    tft.print("SD Faild!");
    delay(2000);
  }
}

static bool smartdelay(unsigned long ms)
{
  bool isOk=false;
  unsigned long start = millis();
  do
  {
    isOk=isOk | feedgps();
  }
  while (millis() - start < ms);
  return isOk;
}

void loop() {

  if(smartdelay(DELAYTIME))
  {
    if(gpsdump(gps))
    {
      hadGPS=true;
      if(isRec)
      {
        savePos();
      }
    }
  }

  getBtnState();
  
  if(hadGPS)
  {
    tft.fillRect(pixelSubX,pixelSubY,2,2,ST7735_BLUE);
    getMovingAverage(&flat,&flon);
    if(!checkMap(flat,flon,level,&mKeyPath,&mKeyName,&mKeyExt,&pixelSubX,&pixelSubY))
    {
      fillMap(tft,myFile,APPROOT,mKeyPath,mKeyName,mKeyExt);
    }
    drawLabels();
    tft.fillRect(pixelSubX,pixelSubY,2,2,ST7735_RED);
  }
  else
  {
    tft.setCursor(16, 40);
    tft.setTextColor(ST7735_RED);
    tft.print("GPS BAD!");
  }

  if(isLED_ON)
  {
    lightOnCout++;
    if(lightOnCout>LEDTIME / DELAYTIME)
    {
      lightOnCout=0;
      isLED_ON=false;
      digitalWrite(TFT_LED, LOW);
    }
  }
}

void drawLabels()
{
  tft.fillRect(46, 129 ,40,9, ST7735_RED);
  tft.setCursor(48, 130);
  tft.setTextColor(ST7735_BLACK);
  tft.print(mDate);

  tft.fillRect(46, 139 ,40,9, ST7735_RED);
  tft.setCursor(48, 140);
  tft.setTextColor(ST7735_BLACK);
  tft.print(mTime);

  tft.fillRect(0, 129 ,45,9, ST7735_GREEN);
  tft.setCursor(2, 130);
  tft.setTextColor(ST7735_BLACK);
  tft.print(flat,3);

  tft.fillRect(0, 139 ,45,9, ST7735_GREEN);
  tft.setCursor(2, 140);
  tft.setTextColor(ST7735_BLACK);
  tft.print(flon,3);

  tft.fillRect(0, 149 ,45,9, ST7735_BLUE);
  tft.setCursor(2, 150);
  tft.setTextColor(ST7735_BLACK);
  tft.print(falt,1);

  tft.fillRect(46, 149 ,45,9, ST7735_BLUE);
  tft.setCursor(48, 150);
  tft.setTextColor(ST7735_BLACK);
  tft.print(fspeed,1);

  tft.fillRect(92, 149 ,36,9, ST7735_BLUE);
  tft.setCursor(94, 150);
  tft.setTextColor(ST7735_BLACK);
  tft.print(fcourse,1);
}

void initButtons()
{
  pinMode(BTNZOOMIN, INPUT);           // set pin to input
  digitalWrite(BTNZOOMIN, HIGH);       // turn on pullup resistors
  pinMode(BTNZOOMOUT, INPUT);           // set pin to input
  digitalWrite(BTNZOOMOUT, HIGH);       // turn on pullup resistors
}

void initTFTLED()
{
  isLED_ON=true;
  pinMode(TFT_LED, OUTPUT);
  digitalWrite(TFT_LED, HIGH);
}

void getBtnState()
{
  if(!digitalRead(BTNZOOMIN))
  {
    if(isLED_ON)
    {
      if(hadGPS)
      {
        level++;
        if(level>MaxLevel)
        {
          level=MaxLevel;
        }
      }
      lightOnCout=0;
    }
    else
    {
      isLED_ON=true;
      digitalWrite(TFT_LED, HIGH);
    }
    delay(200);
  }
  else if(!digitalRead(BTNZOOMOUT))
  {
    if(isLED_ON)
    {
      if(hadGPS)
      {
        delay(CHECKHOLDTIME);
        if(!digitalRead(BTNZOOMOUT))  //hold
        {
          if(isRec)
          {
            isRec=false;
            tft.fillRect(98, 139 ,36,9,  ST7735_BLACK);
          }
          else
          {
            initFile();
            isRec=true;
            tft.fillRect(98, 139 ,36,9, ST7735_RED);
            tft.setCursor(100, 140);
            tft.setTextColor(ST7735_BLACK);
            tft.print("REC");
          }
        }
        else  //click
        {
          level--;
          if(level<MinLevel)
          {
            level=MinLevel;
          }
        }
      }
      lightOnCout=0;
    }
    else
    {
      isLED_ON=true;
      digitalWrite(TFT_LED, HIGH);
    }
    delay(200);
  }
}

void initFile()
{
  if(!sd.exists(TRACK))
  {
    if (myFile.open(TRACK, O_RDWR | O_CREAT | O_AT_END)) {
      myFile.println("Date,Time,Lon,Lat,Alt,Speed,Course");
      myFile.close();
    }
  }
}

void savePos()   
{
  if (myFile.open(TRACK, O_RDWR | O_CREAT | O_AT_END)) {
    myFile.print(mDate);
    myFile.print(',');
    myFile.print(mTime);
    myFile.print(',');
    myFile.print(flon,6);
    myFile.print(',');
    myFile.print(flat,6);
    myFile.print(',');
    myFile.print(falt,1);
    myFile.print(',');
    myFile.print(fspeed,1);
    myFile.print(',');
    myFile.println(fcourse,1);
    myFile.close();
  }
}





















[/kenrobot_code]






本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-3-29 10:15 , Processed in 0.042434 second(s), 18 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表