Changeset 197 for rtos_arduino/trunk/examples/Basic
- Timestamp:
- Mar 30, 2016, 4:58:30 PM (8 years ago)
- Location:
- rtos_arduino/trunk/examples/Basic
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
rtos_arduino/trunk/examples/Basic/Makefile
r136 r197 27 27 # ã©ã¤ãã©ãªã®ä½¿ç¨ 28 28 # 29 #USE_ARDUINO_SPI = true29 USE_ARDUINO_SPI = true 30 30 #USE_ARDUINO_NCESCAN = true 31 #USE_ARDUINO_SD = true31 USE_ARDUINO_SD = true 32 32 #USE_ARDUINO_TFT = true 33 33 #USE_ETHERNET2 = true 34 34 #USE_NAXESMOTION = true 35 USE_ARDUINO_RTC = true 35 #USE_ARDUINO_RTC = true 36 #USE_WIRE = true 36 37 37 38 # -
rtos_arduino/trunk/examples/Basic/rca_app.cpp
r136 r197 10 10 //#define ANALOGREAD 11 11 //#define RTC_ALARM 12 //#define SD_CARD 12 13 13 14 #ifdef BLINK … … 309 310 } 310 311 #endif /* RTC_ALARM */ 312 313 314 #ifdef SD_CARD 315 /* 316 SD card datalogger 317 318 This example shows how to log data from three analog sensors 319 to an SD card using the SD library. 320 321 The circuit: 322 * analog sensors on analog ins 0, 1, and 2 323 * SD card attached to SPI bus as follows: 324 ** MOSI - pin 11 325 ** MISO - pin 12 326 ** CLK - pin 13 327 ** CS - pin 4 328 329 created 24 Nov 2010 330 modified 9 Apr 2012 331 by Tom Igoe 332 333 This example code is in the public domain. 334 335 */ 336 337 #include <SPI.h> 338 #include <SD.h> 339 340 // On the Ethernet Shield, CS is pin 4. Note that even if it's not 341 // used as the CS pin, the hardware CS pin (10 on most Arduino boards, 342 // 53 on the Mega) must be left as an output or the SD library 343 // functions will not work. 344 const int chipSelect = 4; 345 346 void setup() 347 { 348 // Open serial communications and wait for port to open: 349 Serial.begin(115200); 350 while (!Serial) { 351 ; // wait for serial port to connect. Needed for Leonardo only 352 } 353 354 Serial.print("Initializing SD card..."); 355 // make sure that the default chip select pin is set to 356 // output, even if you don't use it: 357 // pinMode(10, OUTPUT); 358 359 // see if the card is present and can be initialized: 360 if (!SD.begin(chipSelect)) { 361 Serial.println("Card failed, or not present"); 362 // don't do anything more: 363 return; 364 } 365 Serial.println("card initialized."); 366 367 if (SD.remove("datalog.txt")) { 368 Serial.println("Delete datalog.txt"); 369 } 370 } 371 372 void loop() 373 { 374 // make a string for assembling the data to log: 375 String dataString = ""; 376 377 // read three sensors and append to the string: 378 for (int analogPin = 0; analogPin < 3; analogPin++) { 379 int sensor = analogRead(analogPin); 380 dataString += String(sensor); 381 if (analogPin < 2) { 382 dataString += ","; 383 } 384 } 385 386 File dataFile = SD.open("datalog.txt"); 387 if (dataFile) { 388 Serial.println("=== data from file ==="); 389 while (dataFile.available()) { 390 Serial.write(dataFile.read()); 391 } 392 dataFile.close(); 393 } 394 395 // open the file. note that only one file can be open at a time, 396 // so you have to close this one before opening another. 397 dataFile = SD.open("datalog.txt", FILE_WRITE); 398 399 // if the file is available, write to it: 400 if (dataFile) { 401 dataFile.println(dataString); 402 dataFile.close(); 403 // print to the serial port too: 404 Serial.println("=== new data to file ==="); 405 Serial.println(dataString); 406 } 407 // if the file isn't open, pop up an error: 408 else { 409 Serial.println("error opening datalog.txt"); 410 } 411 delay(4000); 412 } 413 #endif /* SD_CARD */ 414 415
Note:
See TracChangeset
for help on using the changeset viewer.