mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-10 12:53:29 +00:00
[cxx]: GPIO CXX wrappers, experiemental CI rule
* Wrapper class for simple GPIO interaction like read/write without ISRs. * Added rule to provoke builds after changes in the experimental C++ component.
This commit is contained in:
39
examples/cxx/experimental/blink_cxx/main/main.cpp
Normal file
39
examples/cxx/experimental/blink_cxx/main/main.cpp
Normal file
@@ -0,0 +1,39 @@
|
||||
/* Blink C++ Example
|
||||
|
||||
This example code is in the Public Domain (or CC0 licensed, at your option.)
|
||||
|
||||
Unless required by applicable law or agreed to in writing, this
|
||||
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||
CONDITIONS OF ANY KIND, either express or implied.
|
||||
*/
|
||||
|
||||
#include <cstdlib>
|
||||
#include <thread>
|
||||
#include "esp_log.h"
|
||||
#include "gpio_cxx.hpp"
|
||||
|
||||
using namespace idf;
|
||||
using namespace std;
|
||||
|
||||
extern "C" void app_main(void)
|
||||
{
|
||||
/* The functions of GPIO_Output throws exceptions in case of parameter errors or if there are underlying driver
|
||||
errors. */
|
||||
try {
|
||||
/* This line may throw an exception if the pin number is invalid.
|
||||
* Alternatively to 4, choose another output-capable pin. */
|
||||
GPIO_Output gpio(GPIONum(4));
|
||||
|
||||
while (true) {
|
||||
printf("LED ON\n");
|
||||
gpio.set_high();
|
||||
this_thread::sleep_for(std::chrono::seconds(1));
|
||||
printf("LED OFF\n");
|
||||
gpio.set_low();
|
||||
this_thread::sleep_for(std::chrono::seconds(1));
|
||||
}
|
||||
} catch (GPIOException &e) {
|
||||
printf("GPIO exception occurred: %s\n", esp_err_to_name(e.error));
|
||||
printf("stopping.\n");
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user