本文整理汇总了C++中SdFat::begin方法的典型用法代码示例。如果您正苦于以下问题:C++ SdFat::begin方法的具体用法?C++ SdFat::begin怎么用?C++ SdFat::begin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SdFat
的用法示例。
在下文中一共展示了SdFat::begin方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: begin
bool Tune::begin()
{
// Pin configuration
pinMode(DREQ, INPUT_PULLUP);
pinMode(XDCS, OUTPUT);
pinMode(XCS, OUTPUT);
pinMode(SDCS, OUTPUT);
// Deselect control & data ctrl
digitalWrite(XCS, HIGH);
digitalWrite(XDCS, HIGH);
// Deselect SD's chip select
digitalWrite(SDCS, HIGH);
// SD card initialization
if (!sd.begin(SDCS, SPI_HALF_SPEED))
{
sd.initErrorHalt(); // describe problem if there's one
return 0;
}
// Tracklisting also return the number of playable files
Serial.print(listFiles());
Serial.print(" tracks found, ");
// SPI bus initialization
SPI.begin();
SPI.setDataMode(SPI_MODE0);
// Both SCI and SDI read data MSB first
SPI.setBitOrder(MSBFIRST);
// From the datasheet, max SPI reads are CLKI/6. Here CLKI = 26MHz -> SPI max speed is 4.33MHz.
// We'll take 16MHz/4 = 4MHz to be safe.
// Plus it's the max recommended speed when using a resistor-based lvl converter with an SD card.
SPI.setClockDivider(SPI_CLOCK_DIV4);
SPI.transfer(0xFF);
delay(10);
// Codec initialization
// Software reset
setBit(SCI_MODE, SM_RESET);
delay(5);
// VS1022 "New mode" activation
setBit(SCI_MODE, SM_SDINEW);
// Clock setting (default is 24.576MHz)
writeSCI(SCI_CLOCKF, 0x32, 0xC8);
delay(5);
// Wait until the chip is ready
while (!digitalRead(DREQ));
delay(100);
// Set playState flag
playState = idle;
// Set volume to avoid hurt ears ;)
setVolume(150);
Serial.println("Tune ready !");
return 1;
}
示例2: beginDataLog
/**
* Function starts the SD card service and makes sure that the appropriate directory
* structure exists, then creates the file to use for logging data. Data will be logged
* to a file called fileNamePrefix_0.csv or fileNamePrefix_0.bin (number will be incremented
* for each new log file)
*
* @param chipSelectPin Arduino pin SD card reader CS pin is attached to
* @param fileNamePrefix string to prefix at beginning of data file
* @param csvData boolean flag whether we are writing csv data or binary data (used for filename)
*
* @return true if successful, false if failed
*/
bool beginDataLog(int chipSelectPin, const char *fileNamePrefix, bool csvData)
{
bool ret;
int i = 0;
int max_len;
char fileName[19];
char prefix[8];
char rootPath[] = "/data";
if (_output_buffer != NULL) {
delete []_output_buffer;
}
OUTPUT_BUF_SIZE = 512;
_output_buffer = vol.cacheAddress()->output_buf;
if (freeMemory() < 400) {
strcpy_P(_getOutBuf(), sd_card_error);
Serial.print(_getOutBuf());
Serial.print(freeMemory());
Serial.println(", need 400)");
ret = false;
} else {
ret = sd.begin(chipSelectPin, SPI_FULL_SPEED);
}
//Filenames need to fit the 8.3 filename convention, so truncate down the
//given filename if it is too long.
memcpy(prefix, fileNamePrefix, 7);
prefix[7] = '\0';
if (ret) {
if (!sd.exists(rootPath))
ret = sd.mkdir(rootPath);
if (ret) {
while (true) {
if (i < 10) {
max_len = 7;
} else if (i < 100) {
max_len = 6;
} else if (i < 1000) {
max_len = 5;
} else {
break;
}
prefix[max_len - 1] = '\0';
sprintf(fileName, "%s/%s%d.%s", rootPath, prefix, i,
csvData ? "csv" : "bin");
if (!sd.exists(fileName)) {
file = sd.open(fileName, FILE_WRITE);
break;
}
i++;
}
}
}
return file.isOpen();
}
示例3: init
void init() {
close();
#ifdef SDCARD
if (!sd.begin(SD_CS, SPI_FULL_SPEED)) {
// error_P("card.init");
return;
}
#endif
}
示例4: init_SD
void init_SD(){
if (!sd.begin(SDCARD_CSPIN, SPI_HALF_SPEED)) {
f.SDCARD = 0; // If init fails, tell the code not to try to write on it
debug[1] = 999;
}
else {
f.SDCARD = 1;
debug[1] = 000;
}
}
示例5: SDBeaconSetup
void TicketflySDBeacon::SDBeaconSetup (SdFat& SD) {
Serial.begin (9600);
Serial.print(F("Initializing SD card..."));
pinMode(10, OUTPUT);
if (!SD.begin(4)) {
Serial.println(F("initialization failed!"));
return;
}
Serial.println(F("initialization done."));
}
示例6: setup
void SDcard::setup(){
Serial.begin(115200);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.print("Initializing SD card...");
pinMode(10,OUTPUT);
if (!SD.begin(4)) {
Serial.println("Initialization failed!");
return;
}
Serial.println("initialization done.");
}
示例7: main
int main()
{
// initialize the SD card at SPI_FULL_SPEED for best performance.
// try SPI_HALF_SPEED if bus errors occur.
if (!sd.begin(SD_ENABLE_PIN, SPI_FULL_SPEED)) sd.initErrorHalt();
if (!myFile.open("test.txt", O_RDWR | O_CREAT | O_AT_END)) {
sd.errorHalt("opening test.txt for write failed");
}
myFile.println("testing 1, 2, 3.");
// close the file:
myFile.close();
while (1);
return 0;
}
示例8: setup
void setup() {
pinMode(D7, OUTPUT);
pinMode(SPEAKER, OUTPUT);
pinMode(BUTTON, INPUT);
Blynk.begin(BLYNK_AUTH);
button.debounceTime = 20;
button.multiclickTime = 20; // Only allow 1 click
button.longClickTime = 2000;
Display.begin();
Display.fillScreen(BLACK);
if(false == sd.begin(SD_CS, SPI_HALF_SPEED)) {
error("Failed to start SD");
return;
}
SdFile::dateTimeCallback(dateTime);
AlarmManager::valueForCallback(valueFor);
Particle.function("alarm", handleAlarm);
}
示例9: begin
boolean begin(uint8_t pin, uint8_t rate){
return sdfat.begin(pin, rate); // .init(rate, pin);
}
示例10: setupSdCard
void setupSdCard() {
// initialize the SD card at full speed
if (!sd.begin(SD_CHIP_SELECT, SPI_FULL_SPEED)) {
Serial.println("No SD card");
}
}
示例11: SD_Init
boolean SD_Init(void)
{
return sdf.begin(chipSelect,SPI_FULL_SPEED);
}
示例12: startBinLogger
void startBinLogger(void (*dateTime)(uint16_t *date, uint16_t *time)){
#ifdef LOGGER_DEBUG
Serial.print("Size of Struct: ");
Serial.println(sizeof(salus_data_t));
Serial.print("Data_DIM: ");
Serial.println(DATA_DIM);
Serial.print("FILL_DIM: ");
Serial.println(FILL_DIM);
Serial.print("Sizeof Block: ");
Serial.println(sizeof(block_t));
Serial.println();
#endif
if (!sd.begin(SD_CHIPSELECT, SD_SPI_SPEED)) {
sd.initErrorHalt();
}
int number = 0;
char sName[80];
// Find a filename that hasn't been used already
do
{
sprintf(sName, "Salus_Results_%d.bin", number++);
} while (sd.exists(sName));
binFile.close();
binFile.dateTimeCallback(dateTime);
if (!binFile.createContiguous(sd.vwd(), sName, 512 * FILE_BLOCK_COUNT)){
error("createContiguous failed");
}
if (!binFile.contiguousRange(&bgnBlock, &endBlock)){
error("contiguousRange failed");
}
// Use SdFat's internal buffer ( ???? )
uint8_t* cache = (uint8_t*)sd.vol()->cacheClear();
if (cache == 0) {
error("cacheClear failed");
}
binFile.dateTimeCallbackCancel();
uint32_t bgnErase = bgnBlock;
uint32_t endErase;
while (bgnErase < endBlock) {
endErase = bgnErase + ERASE_SIZE;
if (endErase > endBlock) {
endErase = endBlock;
}
if (!sd.card()->erase(bgnErase, endErase)) {
error("erase failed");
}
bgnErase = endErase + 1;
}
// Start a multiple block write.
if (!sd.card()->writeStart(bgnBlock, FILE_BLOCK_COUNT)) {
error("writeBegin failed");
}
}
示例13: begin
void OpenSprinkler::begin() {
// shift register setup
pinMode(PIN_SR_OE, OUTPUT);
// pull shift register OE high to disable output
digitalWrite(PIN_SR_OE, HIGH);
pinMode(PIN_SR_LATCH, OUTPUT);
digitalWrite(PIN_SR_LATCH, HIGH);
pinMode(PIN_SR_CLOCK, OUTPUT);
#if defined(OSPI)
pin_sr_data = PIN_SR_DATA;
// detect RPi revision
unsigned int rev = detect_rpi_rev();
if (rev==0x0002 || rev==0x0003)
pin_sr_data = PIN_SR_DATA_ALT;
// if this is revision 1, use PIN_SR_DATA_ALT
pinMode(pin_sr_data, OUTPUT);
#else
pinMode(PIN_SR_DATA, OUTPUT);
#endif
// Reset all stations
clear_all_station_bits();
apply_all_station_bits();
// pull shift register OE low to enable output
digitalWrite(PIN_SR_OE, LOW);
// Rain sensor port set up
pinMode(PIN_RAINSENSOR, INPUT);
#if defined(ARDUINO)
digitalWrite(PIN_RAINSENSOR, HIGH); // enabled internal pullup on rain sensor
#else
// RPI and BBB have external pullups
#endif
// Default controller status variables
// AVR assigns 0 to static variables by default
// so only need to initialize non-zero ones
status.enabled = 1;
status.safe_reboot = 0;
old_status = status;
nvdata.sunrise_time = 360; // 6:00am default sunrise
nvdata.sunset_time = 1080; // 6:00pm default sunset
nboards = 1;
nstations = 8;
// set rf data pin
pinMode(PIN_RF_DATA, OUTPUT);
digitalWrite(PIN_RF_DATA, LOW);
/*pinMode(PIN_RELAY, OUTPUT);
digitalWrite(PIN_RELAY, LOW);*/
hw_type = HW_TYPE_AC;
#if defined(ARDUINO) // AVR SD and LCD functions
// Init I2C
Wire.begin();
#if defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega1284__) // OS 2.3 specific detections
uint8_t ret;
// detect hardware type
Wire.beginTransmission(MAC_CTRL_ID);
Wire.write(0x00);
ret = Wire.endTransmission();
if (!ret) {
Wire.requestFrom(MAC_CTRL_ID, 1);
while(!Wire.available());
ret = Wire.read();
if (ret == HW_TYPE_AC || ret == HW_TYPE_DC || ret == HW_TYPE_LATCH) {
hw_type = ret;
} else {
// hardware type is not assigned
}
}
if (hw_type == HW_TYPE_DC) {
pinMode(PIN_BOOST, OUTPUT);
digitalWrite(PIN_BOOST, LOW);
pinMode(PIN_BOOST_EN, OUTPUT);
digitalWrite(PIN_BOOST_EN, LOW);
}
#endif
lcd_start();
// define lcd custom icons
byte _icon[8];
// WiFi icon
_icon[0] = B00000;
_icon[1] = B10100;
_icon[2] = B01000;
//.........这里部分代码省略.........
示例14: setup
/*
* Setup
*/
void setup() {
wdt_enable(WDTO_8S);
wdt_reset();
//Setup Ports
Serial.begin(115200); //Start Debug Serial 0
Serial1.begin(9600); //Start GPS Serial 1
Serial2.begin(9600);
pinMode(PIN_LED_GREEN, OUTPUT); //Blue GREEN
pinMode(PIN_LED_RED, OUTPUT); //Blue RED
pinMode(PIN_LED_BLUE, OUTPUT); //Blue LED
pinMode(PIN_SPI_CS,OUTPUT); //Chip Select Pin for the SD Card
pinMode(10, OUTPUT); //SDcard library expect 10 to set set as output.
// Initialise the GPS
wdt_disable();
gps.init();
gps.configureUbloxSettings(); // Configure Ublox for MY_HIGH altitude mode
wdt_enable(WDTO_8S);
// join I2C bus //start I2C transfer to the Module/Transmitter
Wire.begin();
//Set up the two EasyTransfer methods
ETI2Cout.begin(details(mD.i2cOut), &Wire); //setup the data structure to transfer out
ETSerialIn.begin(details(vals), &Serial2);
//Start up the LGgyro
if (LGgyro.init()) {
#ifdef DEBUG_ON
Serial.println("LGgyro OK");
#endif
LGgyro.enableDefault();
} else {
#ifdef DEBUG_ON
Serial.println("LGgyro not working");
#endif
SET_LED_Status(SET_LED_WHITE,500); //White LED
SET_LED_Status(SET_LED_RED,1000); //Red LED
}
//Start up the accelerometer
accel = ADXL345(); // Create an instance of the accelerometer
if(accel.EnsureConnected()) { // Check that the accelerometer is connected.
#ifdef DEBUG_ON
Serial.println("Connected to ADXL345.");
#endif
accel.SetRange(2, true); // Set the range of the accelerometer to a maximum of 2G.
accel.EnableMeasurements(); // Tell the accelerometer to start taking measurements.
} else{
#ifdef DEBUG_ON
Serial.println("Could not connect to ADXL345.");
#endif
SET_LED_Status(SET_LED_WHITE,500); //White LED
SET_LED_Status(SET_LED_RED,2000); //Red LED
}
//Start up the compass
compass = HMC5883L(); // Construct a new HMC5883 compass.
#ifdef DEBUG_ON
if(compass.EnsureConnected() == 1) {
Serial.println("Connected to HMC5883L.");
} else {
Serial.println("Not Connected to HMC5883L.");
}
#endif
error = compass.SetScale(1.3); // Set the scale of the compass.
#ifdef DEBUG_ON
if(error != 0) { // If there is an error, print it out.
Serial.println("Compass Error 1");
Serial.println(compass.GetErrorText(error));
} else {
Serial.println("Compass Ok 1");
}
#endif
error = compass.SetMeasurementMode(Measurement_Continuous); // Set the measurement mode to Continuous
#ifdef DEBUG_ON
if(error != 0) { // If there is an error, print it out.
Serial.println("Compass error 2");
Serial.println(compass.GetErrorText(error));
} else {
Serial.println("Compass Ok 2");
}
#endif
//Start up the Pressure Sensor
dps = BMP085();
dps.init();
#ifdef DEBUG_ON
Serial.print("BMP Mode ");
Serial.println(dps.getMode());
#endif
wdt_reset();
// Start up the OneWire Sensors library and turn off blocking takes too long!
sensors.begin();
sensors.setWaitForConversion(false);
sensors.requestTemperaturesByAddress(outsideThermometer); // Send the command to get temperature
//Initialise all of the record values
//.........这里部分代码省略.........
示例15:
boolean MP3Player::Init(byte CS_uSD,byte ASD)
{
PLAY = false;
isPlayAll = false;
name.reserve(80);
name = "";
vol = 0;
counter=0;
currentDir.reserve(20);
currentDir = "";
_isPause = false;
_isMute = false;
ls_flag = false;
CS_SD=CS_uSD;
AMP=ASD;
pinMode(CS,OUTPUT); //STA013CS
digitalWrite(CS,LOW); //deactivate sta013 spi input
pinMode(DATREQ,INPUT); //DATREQ
pinMode(RESET,OUTPUT); //reset
digitalWrite(RESET,HIGH);
pinMode(AMP,INPUT); //shutdown the amp
pinMode(CS_SD, OUTPUT); //SPI uSD CS
InitI2C();
Reset_STA013();
#if DEBUG
Serial.begin(9600);
while (!Serial) ; // wait for serial port to connect. Needed for Leonardo only
#endif
if (!sd.begin(CS_SD, SPI_FULL_SPEED))
{
#if DEBUG
sd.initErrorHalt();
#endif
return false;
}
SPI.begin();
boolean stat=Verify_STA013();
if (stat==false)
{
#if DEBUG
Serial.println("STA013 not exist!");
#endif
return false;
}
else
{
#if DEBUG
Serial.println("STA013 verified..");
#endif
if(!Setup_STA013())
{
return false;
}
else
{
delayMicroseconds(100000);
setVolume(220); // set volume by default in case user forgets to set it.
AMPON();
return true;
}
}
}