|

楼主 |
发表于 2019-9-26 11:52
|
显示全部楼层
[mw_shl_code=arduino,true]/*
【Arduino】108种传感器模块系列实验(资料+代码+图形+仿真)
实验一百二十五: 升级版 WeMos D1 R2 WiFi UNO 开发板 基于ESP8266
项目:ESP8266闪烁,由Daniel Salazar轮询超时
*/
#include < olledTimeout.h>
void ledOn() {
digitalWrite(LED_BUILTIN, LOW); // Turn the LED on (Note that LOW is the voltage level
}
void ledOff() {
digitalWrite(LED_BUILTIN, HIGH); // Turn the LED off by making the voltage HIGH
}
void ledToggle() {
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN)); // Change the state of the LED
}
esp8266::polledTimeout::periodicFastUs halfPeriod(500000); //use fully qualified type and avoid importing all ::esp8266 namespace to the global namespace
// the setup function runs only once at start
void setup() {
Serial.begin(115200);
Serial.println();
Serial.printf("periodic/oneShotMs::timeMax() = %u ms\n", (uint32_t)esp8266::polledTimeout::periodicMs::timeMax());
Serial.printf("periodic/oneShotFastMs::timeMax() = %u ms\n", (uint32_t)esp8266::polledTimeout::periodicFastMs::timeMax());
Serial.printf("periodic/oneShotFastUs::timeMax() = %u us\n", (uint32_t)esp8266::polledTimeout::periodicFastUs::timeMax());
Serial.printf("periodic/oneShotFastNs::timeMax() = %u ns\n", (uint32_t)esp8266::polledTimeout::periodicFastNs::timeMax());
#if 0 // 1 or debugging polledTimeoutf
Serial.printf("periodic/oneShotMs::rangeCompensate = %u\n", (uint32_t)esp8266::polledTimeout::periodicMs::rangeCompensate);
Serial.printf("periodic/oneShotFastMs::rangeCompensate = %u\n", (uint32_t)esp8266::polledTimeout::periodicFastMs::rangeCompensate);
Serial.printf("periodic/oneShotFastUs::rangeCompensate = %u\n", (uint32_t)esp8266::polledTimeout::periodicFastUs::rangeCompensate);
Serial.printf("periodic/oneShotFastNs::rangeCompensate = %u\n", (uint32_t)esp8266::polledTimeout::periodicFastNs::rangeCompensate);
#endif
pinMode(LED_BUILTIN, OUTPUT); // Initialize the LED_BUILTIN pin as an output
using esp8266::polledTimeout: neShotMs; //import the type to the local namespace
//STEP1; turn the led ON
ledOn();
//STEP2: wait for ON timeout
oneShotMs timeoutOn(2000);
while (!timeoutOn) {
yield();
}
//STEP3: turn the led OFF
ledOff();
//STEP4: wait for OFF timeout to assure the led is kept off for this time before exiting setup
oneShotMs timeoutOff(2000);
while (!timeoutOff) {
yield();
}
//Done with STEPs, do other stuff
halfPeriod.reset(); //halfPeriod is global, so it gets inited on sketch start. Clear it here to make it ready for loop, where it's actually used.
}
// the loop function runs over and over again forever
void loop() {
if (halfPeriod) {
ledToggle();
}
}[/mw_shl_code]
|
|