0
A
回答
0
#include <EEPROM.h> // library to access the onboard EEPROM
const int debounceTime = 15000; // debounce time in microseconds
int buttonPin = 5; // pushbutton connected to digital pin 5
int eeAddress = 0; // Address in the eeprom to store the data.
volatile unsigned long time; // variable to store the time since the program started
volatile boolean timeRecorded = false; // used to know when to save value
volatile unsigned long last_Rising; // used to debounce button press
void setup()
{
pinMode(buttonPin, INPUT); // sets the digital pin 5 as input
attachInterrupt(buttonPin, debounce, RISING);
}
void loop()
{
// Only want write when a time is saved
if(valueRecorded)
{
EEPROM.put(eeAddress, time);
valueRecorded = false;
}
}
void debounce()
{
if((micros() - last_Rising) >= debouncing_time)
{
getTime(); // call actual method to fetch and save time
last_Rising = micros();
}
}
void getTime()
{
time = millis();
valueRecorded = true;
}
这个答案作以下假设:正在使用
- 一个Arduino的乌诺。
- 将一个瞬时开关(或按钮)连接到数字引脚5,使得当开关处于“导通”位置时,5v信号将被施加到引脚5,而0v信号将被施加到引脚5时开关处于“关”的位置。
- 您的目标是在机载eeprom中记录上次发生按钮更改状态的时间。
此代码使用中断来捕捉从“关”到“开”的转换。开关的机械特性需要去除输入(https://en.wikipedia.org/wiki/Switch#Contact_bounce)。
要从eeprom中读取值,您将同样使用EEPROM.get(eeAddress, time)
这会将保存在eeprom中的值存储在变量time
中。
此代码也没有规定处理实际的日历时间。Arduino游乐场有一个时间库(http://playground.arduino.cc/code/time),虽然它显然过时了。一个“时间”库链接到该页面上,并具有如何使用它提供日历时间的文档,但是,每次重新启动Arduino时都需要设置和同步时间。
相关问题
- 1. Arduino EEPROM写入和读取阵列?
- 2. 将数据写入Arduino EEPROM
- 3. 将数据写入Arduino的板载EEPROM
- 4. 在linux上读写spi eeprom
- 5. 阵列在Arduino
- 6. PIC18F46J50 EEPROM读/写
- 7. 写入EEPROM PIC?
- 8. Arduino EEPROM看起来很脆,应该写两遍吗?
- 9. Arduino Uno - EEPROM地址不一致
- 10. 使用EEPROM计数到20,000 Arduino Uno
- 11. Arduino的3D阵列
- 12. 在ubuntu上读取,写入,更新pci卡上的eeprom
- 13. Arduino通过多维阵列
- 14. Arduino Uno阵列失败
- 15. Arduino二元阵列太大
- 16. 带阵列的Arduino C++类
- 17. 写入EEPROM的算法?
- 18. PIC16F84 - eeprom读取和写入
- 19. PIC编程器写入EEPROM
- 20. 在Nodemcu EEPROM上存储
- 21. 在Arduino IDE中使用阵列
- 22. 如何添加到阵列在Arduino
- 23. 如何在EEPROM(Arduino IDE)中存储负数?
- 24. 如何在arduino上写测验
- 25. Arduino从EEPROM读取json /将uint8_t转换为字符
- 26. 写入阵列
- 27. Arduino字符阵列映射重叠
- 28. Arduino,最大阵列大小> 255?
- 29. Arduino副函数计算阵列
- 30. 如何比较字符阵列与arduino