如何使内置LED系统闪烁?

时间:2018-12-03 06:09:44

标签: arduino

我试图在记录数据并将其放入EEPROM时使arduino上的内置LED每1秒闪烁一次,但是我不确定该怎么做。我应该每分钟将数据打印到EEPROM,直到EEPROM装满为止,而在此期间,我的内置LED应该闪烁约1秒钟。我的问题似乎是我设置了延迟时间以延迟将数据存储在EEPROM中的时间,但是这也影响了LED闪烁所需的时间,因为它在等待数据存储时闪烁。任何帮助将不胜感激,代码如下:

#include<EEPROM.h>
const int SWITCH = 4;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  pinMode(LED_BUILTIN, OUTPUT);
  pinMode(SWITCH, INPUT_PULLUP);

}

void loop() {
  // put your main code here, to run repeatedly:
  int addr = 0;
  float v;
  float c;
  int t = 0;
  int r = analogRead(0);

  if (digitalRead(SWITCH) == LOW) {
    Serial.println("----Recording----");
    while (addr <= 1024) {
      Serial.println(r);
      EEPROM.put(addr, r);
      addr = addr + 2;
      delay(600);
    }
    while (true);

  }
  else {
    Serial.println("----Replaying----");
    Serial.println("Time(s), Temp(C)");
    while (addr <= 1024) {
      t = t + 1;
      EEPROM.get(addr, r);
      addr = addr + 2;
      v = r * 5.0 / 1024.0;
      c = 100 * (v - 0.5);
      Serial.print(t * 60);
      Serial.print("\t");
      Serial.println(c);
      delay(1000);
    }
    while (true);
  }
}

0 个答案:

没有答案