|
本帖最後由 joejoe2829 於 2014-11-20 14:51 編輯
若不開監看視窗來看Serial.println的執行結果
UNO上的led(pin 13腳)就不會正常的動作
但,開啟監看視窗led燈就又正常的依照程式所寫的動作
是我哪裡有寫錯嗎??還是我哪裡的邏輯有問題??
- #include <SPI.h>
- #include <SD.h>
- const int chipSelect = 4;
- String dataString = "", fileName = "";
- File dataFile;
- int analogPin, sensor, i;
- const int led = 13;
- unsigned long startTime, duration;
- void setup()
- {
- Serial.begin(9600);
- pinMode(led, OUTPUT);
- pinMode(10, OUTPUT);
- if (!SD.begin(chipSelect)) {
- return;
- }
- }
- void loop()
- {
- if (analogRead(0) > 520) {
- digitalWrite(led, HIGH);
- Serial.println("LED ON");
- delay (500);digitalWrite(led, LOW);
- Serial.println("LED OFF");
- delay (500);
- dataFile = SD.open("datalog.csv", FILE_WRITE);
- if (dataFile) {
- dataFile.println("Analog 0,Analog 1");
- startTime = millis();
- while (analogRead(0) > 520) {
- for (analogPin = 0; analogPin < 2; analogPin++) {
- sensor = analogRead(analogPin);
- dataString += String(sensor);
- if (analogPin < 1) {
- dataString += ",";
- }
- }
- dataFile.println(dataString);
- dataString = "";
- }
- duration = millis() - startTime;
- dataFile.print("Duration(ms): ");
- dataFile.println(duration);
- }
- } else {
- dataFile.close();
- digitalWrite(led, LOW);
- Serial.println("LED OFF");
- delay (500);
- }
- }
複製代碼
AIDatalog.ino
(2.59 KB, 下載次數: 1056)
|
|