1 /* ESP Timer C++ Example 2 3 This example code is in the Public Domain (or CC0 licensed, at your option.) 4 5 Unless required by applicable law or agreed to in writing, this 6 software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 7 CONDITIONS OF ANY KIND, either express or implied. 8 */ 9 10 #include <iostream> 11 #include <thread> 12 #include <chrono> 13 14 #include "esp_timer_cxx.hpp" 15 #include "esp_exception.hpp" 16 17 using namespace std; 18 using namespace idf; 19 using namespace idf::esp_timer; 20 app_main(void)21extern "C" void app_main(void) 22 { 23 try { 24 cout << "Setting up timer to trigger in 500ms" << endl; 25 ESPTimer timer([]() { cout << "timeout" << endl; }); 26 timer.start(chrono::microseconds(200 * 1000)); 27 28 this_thread::sleep_for(std::chrono::milliseconds(550)); 29 30 cout << "Setting up timer to trigger periodically every 200ms" << endl; 31 ESPTimer timer2([]() { cout << "periodic timeout" << endl; }); 32 timer2.start_periodic(chrono::microseconds(200 * 1000)); 33 34 this_thread::sleep_for(std::chrono::milliseconds(1050)); 35 } catch (const ESPException &e) { 36 cout << "Exception with error: " << e.error << endl; 37 } 38 } 39