Add SD card to demonstrate how to use the second SPI device

pull/72/head
lewis he 2020-06-29 15:15:04 +08:00
rodzic 7d9561e308
commit 7434da46da
1 zmienionych plików z 54 dodań i 7 usunięć

Wyświetl plik

@ -34,6 +34,47 @@ char buff[512];
int vref = 1100;
int btnCick = false;
#define ENABLE_SPI_SDCARD
//Uncomment will use SDCard, this is just a demonstration,
//how to use the second SPI
#ifdef ENABLE_SPI_SDCARD
#include "FS.h"
#include "SD.h"
#include <SPI.h>
SPIClass SPI1(HSPI);
#define MY_CS 33
#define MY_SCLK 25
#define MY_MISO 27
#define MY_MOSI 26
void setupSDCard()
{
SPI1.begin(MY_SCLK, MY_MISO, MY_MOSI, MY_CS);
//Assuming use of SPI SD card
if (!SD.begin(MY_CS, SPI1)) {
Serial.println("Card Mount Failed");
tft.setTextColor(TFT_RED);
tft.drawString("SDCard Mount FAIL", tft.width() / 2, tft.height() / 2 - 32);
tft.setTextColor(TFT_GREEN);
} else {
tft.setTextColor(TFT_GREEN);
Serial.println("SDCard Mount PASS");
tft.drawString("SDCard Mount PASS", tft.width() / 2, tft.height() / 2 - 48);
String size = String((uint32_t)(SD.cardSize() / 1024 / 1024)) + "MB";
tft.drawString(size, tft.width() / 2, tft.height() / 2 - 32);
}
}
#else
#define setupSDCard()
#endif
void wifi_scan();
//! Long time delay, it is recommended to use shallow sleep, which can effectively reduce the current consumption
void espDelay(int ms)
{
@ -160,6 +201,7 @@ void setup()
tft.pushImage(0, 0, 240, 135, ttgo);
espDelay(5000);
tft.setRotation(0);
tft.fillScreen(TFT_RED);
espDelay(1000);
@ -182,8 +224,13 @@ void setup()
Serial.println("Default Vref: 1100mV");
}
tft.fillScreen(TFT_BLACK);
tft.setTextDatum(MC_DATUM);
setupSDCard();
tft.drawString("LeftButton:", tft.width() / 2, tft.height() / 2 - 16);
tft.drawString("[WiFi Scan]", tft.width() / 2, tft.height() / 2 );
tft.drawString("RightButton:", tft.width() / 2, tft.height() / 2 + 16);