Recommend a quick and easy-to-use led drive pack.

Created at 2020-12-10 22:13:14

Forwarded from RT-Thread Community Developer JQRR_7669

Quick Led

1.Introduction

Quick Led is designed to provide a quick and easy-to-use led drive pack.

1.1Category

qled
├───inc                           // Header file category
│   |   qled.h                    // API header file
│   └───qled_sample.h             // Sample header file
├───src                           // Souce code category
│   |   qled.c                    // Mian module
│   └───qled_samplec              // Sample module
│    license                      // Package license
│    readme.md                    // Package Instruction
└───SConscript                    // RT-Thread default script construction

1.2Licese

Quick Led package applies LGPLv2.1 license, for more details please check the LICENSE file.

1.3Dependence

  • RT_Thread 4.0

2.Usage

2.1Description of the interface function

int qled_add(int pin, int level);

  • Function: Add an led to the driver
  • Parameter:Pin number used by the pin-led
  • Parameter: level - light up the level of the led
  • Return:0-- Success, Other -- Error

void qled_remove(int pin);

  • Function: Remove the led from the drive
  • Parameter: Pin number used by the pin-led
  • Return: None

int qled_set_off(int pin);

  • Function: Set the led to normally out state
  • Parameter: Pin number used by the pin-led
  • Return:0-- Success, Other -- Error

int qled_set_on(int pin);

  • Function: Set the led to normally on state
  • Parameter: Pin number used by the pin-led
  • Return:0-- Success, Other -- Error

int qled_set_blink(int pin, int ton_ms, int toff_ms);

  • Function: Set the led to a periodic flashing state
  • Parameter: Pin number used by the pin-led
  • Parameter: ton_ms--led lit on for a long time
  • Parameter: toff_ms--led lit off for a long time
  • Return:0-- Success, Other -- Error

int qled_set_special(int pin, const u16 datas, int data_total, void (over_cb)(void));

  • Function: Set the led to perform a special sequence flicker
  • Parameter: Pin number used by the pin-led
  • Parameter:datas--Special sequence data
  • Parameters: data_total--for a total special sequence
  • Parameters: over_cb--Callback function at the end of a special sequence execution
  • Return:0-- Success, Other -- Error

2.2Use Sample

Sample 1. Control led flicker with specified frequency and duty ratio

qled_add(24, 1);//Add the No.24 pin led to the drive, high level lit on

qled_set_blink(24, 50, 50);//Set the led to flash at 10Hz, light 50ms, off 50ms
rt_thread_mdelay(5000);// 5s

qled_set_blink(24, 50, 450);//Set the led to flash at 2Hz, light 50ms, off 50ms
rt_thread_mdelay(10000);//10s

qled_remove(24);//The led is no longer needed and removed from the drive

Sample2. Send SOS

#define QLED_SOS_PIN GET_PIN(B, 9) //No.25

static int sos_send_times = 0;//Count of the number of sos signals sent
static const u16 sos_datas[] = //Define the sos signal time data
{
    200, 200, 200, 200, 200, 200,       //short 3 times
    600, 600, 600, 600, 600, 600,       //long 3 times
    200, 200, 200, 200, 200, 200 + 2000 //short 3 times and 2000ms interval
};

static void qled_sos_cb(void)//Define special sequences, execution ends, callback functions
{
    sos_send_times--;
    if (sos_send_times > 0)//The number of executions did not reach
    {
        qled_set_special(QLED_SOS_PIN, sos_datas, sizeof(sos_datas)/sizeof(u16), qled_sos_cb);//Execute again
    }
    else//Execute completed
    {
        qled_remove(QLED_SOS_PIN);//No longer needed, remove from the driver
    }
}

void qled_send_sos(void)//The execution sends the sos signal, sends the SOS signal 5 times, and takes a total of 40s
{
    sos_send_times = 5;//Set the number of sends to 5
    qled_add(QLED_SOS_PIN, 1);//Add pin led to drive
    qled_set_special(QLED_SOS_PIN, sos_datas, sizeof(sos_datas)/sizeof(u16), qled_sos_cb);//Start performing a special sequence
}

2.3Obtain the components

  • Mode 1:

Open the package and configure the parameters as needed by opening the package with the .Env configuration path: RT-Thread online packages -> peripherals packages -> quick led

2.4Configuration parameters

1.png

更多

Follower
0
Views
618
0 Answer
There is no answer, come and add the answer

Write Your Answer

Log in to publish your answer,Click here to log in.

Create
Post

Share