mirror of
https://gitee.com/beecue/fastbee.git
synced 2025-12-19 17:35:54 +08:00
添加智能灯固件代码
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
# The following lines of boilerplate have to be in your project's CMakeLists
|
||||
# in this exact order for cmake to work correctly
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
|
||||
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||
project(morse_code)
|
||||
@@ -0,0 +1,9 @@
|
||||
#
|
||||
# This is a project Makefile. It is assumed the directory this Makefile resides in is a
|
||||
# project subdirectory.
|
||||
#
|
||||
|
||||
PROJECT_NAME := morse_code
|
||||
|
||||
include $(IDF_PATH)/make/project.mk
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
# RMT Transmit Example -- Morse Code
|
||||
|
||||
(See the README.md file in the upper level 'examples' directory for more information about examples.)
|
||||
|
||||
This example mainly illustrates how to transmit the [Morse code](https://en.wikipedia.org/wiki/Morse_code) using the RMT driver.
|
||||
|
||||
## How to Use Example
|
||||
|
||||
### Hardware Required
|
||||
|
||||
* A development board with ESP32 SoC (e.g., ESP32-DevKitC, ESP-WROVER-KIT, etc.)
|
||||
* A USB cable for Power supply and programming
|
||||
* A LED, a speaker or an earphone
|
||||
|
||||
Connection :
|
||||
|
||||
```
|
||||
330R LED
|
||||
GPIO18 +----/\/\/\----+------|>|-----+ GND
|
||||
|
|
||||
| /|
|
||||
+-+ | Speaker
|
||||
| | | or
|
||||
+-+ | earphone
|
||||
| \|
|
||||
|
|
||||
+--------------+ GND
|
||||
```
|
||||
|
||||
### Configure the Project
|
||||
|
||||
Open the project configuration menu (`idf.py menuconfig`).
|
||||
|
||||
In the `Example Connection Configuration` menu:
|
||||
|
||||
* Set the GPIO number used for transmitting the IR signal under `RMT TX GPIO` optin.
|
||||
|
||||
### Build and Flash
|
||||
|
||||
Run `idf.py -p PORT flash monitor` to build, flash and monitor the project.
|
||||
|
||||
(To exit the serial monitor, type ``Ctrl-]``.)
|
||||
|
||||
See the [Getting Started Guide](https://docs.espressif.com/projects/esp-idf/en/latest/get-started/index.html) for full steps to configure and use ESP-IDF to build projects.
|
||||
|
||||
|
||||
## Example Output
|
||||
|
||||
To be able to see and hear the message output by the RMT, connect an LED and a speaker or an earphone (be careful it might make a large noise) to the GPIO you set in the menuconfig.
|
||||
|
||||
Run the example, you will see the following output log:
|
||||
|
||||
``` bash
|
||||
...
|
||||
I (304) example: Configuring transmitter
|
||||
I (2814) example: Transmission complete
|
||||
...
|
||||
```
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
For any technical queries, please open an [issue] (https://github.com/espressif/esp-idf/issues) on GitHub. We will get back to you soon.
|
||||
@@ -0,0 +1,2 @@
|
||||
idf_component_register(SRCS "morse_code_main.c"
|
||||
INCLUDE_DIRS ".")
|
||||
@@ -0,0 +1,7 @@
|
||||
menu "Example Configuration"
|
||||
config EXAMPLE_RMT_TX_GPIO
|
||||
int "RMT TX GPIO"
|
||||
default 18
|
||||
help
|
||||
Set the GPIO number used for transmitting the RMT signal.
|
||||
endmenu
|
||||
@@ -0,0 +1,4 @@
|
||||
#
|
||||
# Main Makefile. This is basically the same as a component makefile.
|
||||
#
|
||||
# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.)
|
||||
@@ -0,0 +1,80 @@
|
||||
/* RMT example -- Morse Code
|
||||
|
||||
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 "sdkconfig.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "esp_log.h"
|
||||
#include "driver/rmt.h"
|
||||
|
||||
static const char *TAG = "example";
|
||||
|
||||
#define RMT_TX_CHANNEL RMT_CHANNEL_0
|
||||
|
||||
/*
|
||||
* Prepare a raw table with a message in the Morse code
|
||||
*
|
||||
* The message is "ESP" : . ... .--.
|
||||
*
|
||||
* The table structure represents the RMT item structure:
|
||||
* {duration, level, duration, level}
|
||||
*
|
||||
*/
|
||||
static const rmt_item32_t morse_esp[] = {
|
||||
// E : dot
|
||||
{{{ 32767, 1, 32767, 0 }}}, // dot
|
||||
{{{ 32767, 0, 32767, 0 }}}, // SPACE
|
||||
// S : dot, dot, dot
|
||||
{{{ 32767, 1, 32767, 0 }}}, // dot
|
||||
{{{ 32767, 1, 32767, 0 }}}, // dot
|
||||
{{{ 32767, 1, 32767, 0 }}}, // dot
|
||||
{{{ 32767, 0, 32767, 0 }}}, // SPACE
|
||||
// P : dot, dash, dash, dot
|
||||
{{{ 32767, 1, 32767, 0 }}}, // dot
|
||||
{{{ 32767, 1, 32767, 1 }}},
|
||||
{{{ 32767, 1, 32767, 0 }}}, // dash
|
||||
{{{ 32767, 1, 32767, 1 }}},
|
||||
{{{ 32767, 1, 32767, 0 }}}, // dash
|
||||
{{{ 32767, 1, 32767, 0 }}}, // dot
|
||||
// RMT end marker
|
||||
{{{ 0, 1, 0, 0 }}}
|
||||
};
|
||||
|
||||
/*
|
||||
* Initialize the RMT Tx channel
|
||||
*/
|
||||
static void rmt_tx_init(void)
|
||||
{
|
||||
rmt_config_t config = RMT_DEFAULT_CONFIG_TX(CONFIG_EXAMPLE_RMT_TX_GPIO, RMT_TX_CHANNEL);
|
||||
// enable the carrier to be able to hear the Morse sound
|
||||
// if the RMT_TX_GPIO is connected to a speaker
|
||||
config.tx_config.carrier_en = true;
|
||||
config.tx_config.carrier_duty_percent = 50;
|
||||
// set audible career frequency of 611 Hz
|
||||
// actually 611 Hz is the minimum, that can be set
|
||||
// with current implementation of the RMT API
|
||||
config.tx_config.carrier_freq_hz = 611;
|
||||
// set the maximum clock divider to be able to output
|
||||
// RMT pulses in range of about one hundred milliseconds
|
||||
config.clk_div = 255;
|
||||
|
||||
ESP_ERROR_CHECK(rmt_config(&config));
|
||||
ESP_ERROR_CHECK(rmt_driver_install(config.channel, 0, 0));
|
||||
}
|
||||
|
||||
void app_main(void *ignore)
|
||||
{
|
||||
ESP_LOGI(TAG, "Configuring transmitter");
|
||||
rmt_tx_init();
|
||||
|
||||
while (1) {
|
||||
ESP_ERROR_CHECK(rmt_write_items(RMT_TX_CHANNEL, morse_esp, sizeof(morse_esp) / sizeof(morse_esp[0]), true));
|
||||
ESP_LOGI(TAG, "Transmission complete");
|
||||
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user