-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d41cedc
commit 919208c
Showing
6 changed files
with
150 additions
and
385 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
//上传该示例之前,请在7号口连接一个LED灯,8号口连接一个无源蜂鸣器的IO端口 | ||
#include <TimersOneForAll.h> | ||
using namespace TimersOneForAll; | ||
constexpr uint8_t LED = 7; | ||
constexpr uint8_t Buzzer = 8; | ||
void setup() | ||
{ | ||
pinMode(7, OUTPUT); | ||
pinMode(8, OUTPUT); | ||
digitalWrite(LED,HIGH); | ||
//设置计时器3在5秒后熄灭LED灯,但不阻断程序 | ||
DoAfter<3,5000,LightDown>(); | ||
//设置4号计时器,每隔2秒,就用5号计时器生成2000㎐脉冲1秒,重复3次 | ||
RepeatAfter<4,2000,PlayTone<5,Buzzer,2000,1000>,3>(); | ||
//设置计时器1,将程序阻断7秒 | ||
Delay<1,7000>(); | ||
//设置计时器1,将LED灯先亮2秒,再熄灭1秒,无限循环 | ||
SquareWave<1,LED,2000,1000>(); | ||
//设置计时器3在8秒后停止计时器1 | ||
DoAfter<3,8000,ShutDown<1>>(); | ||
//观察到,LED灯明暗循环两次后,最终停在了亮状态,因为1号计时器尚未触发暗事件就被停止了 | ||
} | ||
void LightDown() | ||
{ | ||
digitalWrite(LED,LOW); | ||
} | ||
void loop() | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#include <TimersOneForAll.h> | ||
using namespace TimersOneForAll; | ||
//上传该示例之前,请确保你的PC准备好收发串口信号 | ||
void setup() | ||
{ | ||
Serial.begin(9600); | ||
//使用1号计时器开始计时 | ||
StartTiming<1>(); | ||
Serial.setTimeout(-1); | ||
} | ||
void loop() | ||
{ | ||
static uint8_t Instruction = 0; | ||
Serial.readBytes(&Instruction, 1); | ||
Serial.write((uint8_t*)&MillisecondsElapsed<1>, 2); | ||
} | ||
//上传后,可以从PC上向串口发送任意单字节,每次发送都会受到一个16位整数,指示经过的毫秒数。达到65535毫秒后会归零。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.