工具:VScode + PlatformIO IDE
注:B站视频学习笔记。
1、继电器
1)硬件电路
2)程序
#include <Arduino.h>
#define RELAY_PIN 15//初始化定时器
hw_timer_t *timer = NULL;void timer_interrupt(){digitalWrite(RELAY_PIN,!digitalRead(RELAY_PIN));
}void setup() {// put your setup code here, to run once://设置为输出模式pinMode(RELAY_PIN,OUTPUT);//初始化定时器timer = timerBegin(0,80,true);//主持中断处理函数timerAttachInterrupt(timer,timer_interrupt,true);//设置定时器模式timerAlarmWrite(timer,500000,true);//启动定时器timerAlarmEnable(timer);
}void loop() {// put your main code here, to run repeatedly:
}
3)结果
2、