add sd card
This commit is contained in:
parent
dda957b763
commit
7e02287892
|
@ -27,4 +27,5 @@ lib_deps =
|
|||
adafruit/Adafruit BusIO@^1.11.3
|
||||
https://github.com/adafruit/Adafruit-GFX-Library
|
||||
arduino-libraries/SD@^1.2.4
|
||||
mathertel/OneButton@^2.0.3
|
||||
mathertel/OneButton@^2.0.3
|
||||
arduino-libraries/SD@^1.2.4
|
|
@ -183,6 +183,13 @@ uint8_t controlmode=0;
|
|||
#define MODE_GAMETRAK 2
|
||||
|
||||
|
||||
// SD Logging
|
||||
#include <SPI.h> //SCK=13, MISO=12, MOSI=11
|
||||
#include <SD.h> //Format sd cart with FAT or FAT16
|
||||
#define SDCHIPSELECT 16
|
||||
boolean datalogging=true;
|
||||
|
||||
|
||||
void updateInputs(unsigned long loopmillis);
|
||||
void updateDisplay(unsigned long loopmillis);
|
||||
void display_show_stats();
|
||||
|
@ -192,8 +199,19 @@ void display_show_menu();
|
|||
|
||||
void setup() {
|
||||
Serial.begin(SERIAL_BAUD); //Debug and Program
|
||||
|
||||
esc.init();
|
||||
|
||||
|
||||
Serial.print("Initializing SD card...");
|
||||
// see if the card is present and can be initialized:
|
||||
if (!SD.begin(SDCHIPSELECT)) {
|
||||
Serial.println("Card failed, or not present");
|
||||
datalogging=false; //disable logging
|
||||
}else{
|
||||
Serial.println("Card initialized.");
|
||||
}
|
||||
|
||||
analogReadResolution(12);
|
||||
|
||||
pinMode(PIN_GAMETRAK_LENGTH_A, INPUT_PULLUP);
|
||||
|
@ -529,6 +547,23 @@ void loop() {
|
|||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
static unsigned long last_datalogging_write=0;
|
||||
if (datalogging) {
|
||||
#define LOGGINGINTERVAL 100
|
||||
if (loopmillis-last_datalogging_write>LOGGINGINTERVAL)
|
||||
{
|
||||
last_datalogging_write=loopmillis;
|
||||
File dataFile = SD.open("datalog.txt", FILE_WRITE);
|
||||
|
||||
if (dataFile) { // if the file is available, write to it
|
||||
dataFile.println("TEST asdf");
|
||||
dataFile.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
esc.update(loopmillis);
|
||||
|
|
Loading…
Reference in New Issue