arduino 复位
本教程将讨论三种复位 arduino 的方法。第一种方法是 arduino 上的复位按钮。第二种方法是 softwarereset
库,第三种是 adafruit 的 sleepydog
库。
使用复位按钮复位 arduino
如果你使用的是 linux,则存在一个错误,该错误会阻止 arduino ide 与 arduino 开发板对话。结果,你无法在 arduino 中上传代码,它将给出一个错误。在这种情况下,你可以使用此方法复位 arduino。
首先,请确保没有集线器将 arduino 直接连接到计算机。使用集线器有时会给你带来错误。现在关闭 arduino 的电源,按住复位按钮,同时再次打开它的电源。这将复位你的 arduino,并且你可以轻松上传其他代码而不会出现任何错误。
使用 softwarereset
库复位 arduino
如果你想使用 sketch
复位 arduino,则可以使用 softwarereset 库轻松复位。该库与 avr
架构兼容,因此你可以将其与 arduino uno、mega、yun、nano 和 leonardo 开发板一起使用。要使用此库,你需要使用 arduino ide 中提供的库管理器
进行安装。
该库有两种复位 arduino 的方法。一种是 standard
方法,该方法将使用看门狗计时器复位 arduino。另一种方法是 simple
方法,该方法将仅重新启动程序。
void loop() {
// all of your code
softwarereset::standard(); // reset using the standard method
softwarereset::simple(); // restart the program
}
请注意,将不会执行在复位代码下方写入的任何代码行。因此,请确保在完成代码后使用 reset。有关更多信息,请阅读库文档。
使用 adafruit sleepydog
库复位 arduino
上面的库仅适用于五个 arduino 开发板。如果你的 arduino 不是其中之一,那么你可以使用此库,因为它支持几乎所有的 arduino 开发板。使用此链接检查 arduino 是否与此库兼容。
#include
void setup() {
// make sure to reset the watchdog before the countdown expires or
// the arduino will reset!
int countdownms = watchdog.enable(4000);
}
void loop() {
// all of your code
}
在上面的代码中,arduino 将在 4 秒钟内复位。你可以使用复位方法复位看门狗。有关更多信息,请阅读库文档。
转载请发邮件至 1244347461@qq.com 进行申请,经作者同意之后,转载请以链接形式注明出处
本文地址:
相关文章
发布时间:2024/03/13 浏览次数:181 分类:c
-
可以使用简单的方法 toint()函数和 serial.parseint()函数将 char 转换为 int。
发布时间:2024/03/13 浏览次数:151 分类:c
-
可以使用 arduino 中的循环制作计数器。
arduino printf 函数
发布时间:2024/03/13 浏览次数:223 分类:c
-
通过使用 sprintf()函数和 serial.print()函数,可以获得与 printf()相同的输出。