极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 13441|回复: 4

[新手求助]SD读写与LED问题

[复制链接]
发表于 2017-6-2 18:39:23 | 显示全部楼层 |阅读模式
使用SD读写完数据后希望通过闪烁LED进行提示,SD卡能读写成功但是LED没有反应,求各位大神指导一二。
代码如下:
  1.   // initialize serial communication at 9600 bits per second:
  2.   Serial.begin(9600);
  3.   
  4.   while (!Serial) {
  5.     ; // wait for serial port to connect. Needed for native USB, on LEONARDO, MICRO, YUN, and other 32u4 based boards.
  6.   }
  7.   Serial.print("Initializing SD card...");

  8.   if (!SD.begin(4)) {
  9.     Serial.println(" failed!");
  10.     return;
  11.   } else {
  12.     Serial.println(" done.");
  13.     if (!SD.exists("17060203.DAT")) {
  14.       cacheFile = SD.open("17060203.DAT", FILE_WRITE);
  15.     } else {
  16.       cacheFile = SD.open("17060203.DAT", O_READ|O_WRITE);
  17.     }
  18.   
  19.     if (cacheFile) {
  20.       if (cacheFile.size() == 0) {
  21.         cacheFile.println("DEV-ID:DL092817234");
  22.         cacheFile.println("DEV-ADDR:192.169.0.1");
  23.         cacheFile.println("DEV-MAC:AC-22-11-CD-AE");
  24.         cacheFile.println("--DATALOG--");
  25.       }
  26.       cacheFile.println("20170602111411,33.2,11.2,502,293,11.2,11,23,11,22,33");
  27.       cacheFile.println("20170602111411,33.2,11.2,502,293,11.2,11,23,11,22,33");
  28.       cacheFile.println("20170602111411,33.2,11.2,502,293,11.2,11,23,11,22,33");
  29.   
  30.       cacheFile.seek(0);
  31.       // read from the file until there's nothing else in it:
  32.       while (cacheFile.available()) {
  33.         Serial.write(cacheFile.read());
  34.       }  
  35.       cacheFile.close();
  36.     } else {
  37.       Serial.println("error opening/creating file.");
  38.     }   
  39.   }

  40.   pinMode(LED_BUILTIN, OUTPUT);
  41.   digitalWrite(LED_BUILTIN, HIGH);
  42.   delay(5000);
  43.   digitalWrite(LED_BUILTIN, LOW);
  44.   delay(3000);
复制代码
回复

使用道具 举报

发表于 2017-6-2 20:52:39 | 显示全部楼层
这不是全部的代码吧
回复 支持 反对

使用道具 举报

 楼主| 发表于 2017-6-3 11:45:58 | 显示全部楼层
zjz5717 发表于 2017-6-2 20:52
这不是全部的代码吧

这个时setup中的代码,loop函数为空的
回复 支持 反对

使用道具 举报

发表于 2017-6-3 13:11:48 | 显示全部楼层
這樣子程式跑完一次,當然不會再繼續囉=結束
回复 支持 反对

使用道具 举报

发表于 2017-6-3 18:30:36 | 显示全部楼层
niijyeni 发表于 2017-6-3 11:45
这个时setup中的代码,loop函数为空的

setup函数只执行一次,所以当舵机转一圈回来之后,会读一次传感器,在之后就不会在读取了,你是不是考虑把读传感器的部分放到loop函数
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-4-26 22:41 , Processed in 0.042651 second(s), 19 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表