쉬운 방법으로 표준 LED를 제어하기위한 Arduino 라이브러리.
Easyled는 on() , off() , toggle() , flash() , isOn() , isOff() 및 reset() 와 같은 간단한 논리적 메소드를 제공합니다.
이 라이브러리는 읽고 이해하기 쉬운 클리너 코드를 작성하는 데 도움이됩니다.
진술 led.on() 사용하여 LED를 켜면 LED를 켤 수 있습니다. 누군가가 그 진술을 읽으면 그것이 무엇을하는지 즉시 명확하게합니다. LED를 켜십시오. Easyled를 사용하면 pinMode() , digitalWrite() , 더 이상 HIGH LOW 사용할 필요가 없습니다.
Easyled없이 digitalWrite(LED_PIN, LOW) 와 같은 문을 사용하여 LED 켜기 (활성 인 경우)를 전환해야합니다. 그 진술을 읽을 때 LED를 켜거나 끄는지는 명확하지 않습니다. 따라서 코드를 읽고 이해하기가 더 어려워집니다. HIGH 거나 LOW 것이 LED가 켜져 있는지 여부를 기억해야합니다. 활성 저장 및 활성 높이 LED를 모두 사용하면 코드를 읽고 이해하기가 더욱 어려워집니다.
LED는 EasyLed 클래스의 인스턴스로 정의됩니다. 생성자는 두 개의 매개 변수가 필요합니다. pin 은 LED가 연결된 GPIO 핀 및 activeLevel 인 핀이 LED가 활성 낮은지 또는 활성 높이인지를 나타냅니다. Enum Value EasyLed::ActiveLevel::Low Active Low와 EasyLed::ActiveLevel::High 활성 높이를 나타냅니다.
온 및 오프 상태의 경우 유사한 열거 값이 사용됩니다. EasyLed::State::On LED가 켜져 있고 EasyLed::State::Off 꺼져 있음을 의미합니다. 열거 값은 LED가 LOW 있는지 또는 꺼져 HIGH 고유하게 식별하지 않기 때문에 상태에 사용됩니다.
선택적으로 세 번째 매개 변수 initialState 지정하여 초기 상태를 ON으로 설정할 수 있습니다 (기본값은 꺼짐). 네 번째 매개 변수 pinmode 도 선택 사항이며 PIN을 출력으로 설정합니다. 이것은 일반적으로 변경되지 않아야합니다 (이를 지원하는 아키텍처에 대해 output_open_drain으로 변경 해야하는 경우를 제외하고) .
GPIO 핀의 상태를 프로그래밍하여 LED가 켜지고 꺼집니다. gpio 핀을 낮은 레벨로 설정하면 LED가 켜거나 끄면 켜질 수 있습니다. GPIO 핀 레벨이 낮을 때 LED가 켜져 있으면이를 활성으로라고합니다. 핀 레벨이 높을 때 LED가 켜져 있으면이를 활성 높이라고합니다. LED가 활성으로 낮은지 또는 활성 높이인지 여부는 LED가 물리적으로 연결되는 방식에 따라 다릅니다. 두 유형 모두 실제로 사용됩니다.
EasyLed (
const uint8_t pin, // GPIO pin to which the LED is connected.
const ActiveLevel activeLevel, // The logic level when the LED is on.
const State initialState = State::Off, // Optional, default is off.
const uint8_t pinmode = OUTPUT // Optional, shall normally not be changed. enum class State {Off, On};
enum class ActiveLevel {Low = LOW, High = HIGH}; void on () // Switch LED on
void off() // Switch LED off
void toggle() // Toggle LED state.
void reset() // Reset LED state to initialState.
void flash( // Flash LED (all parameters are optional)
const uint8_t count = 2 , // Number of flashes
const uint16_t onTimeMs = 160 , // on-time duration in milliseconds
const uint16_t offTimeMs = 160 , // off-time duration in milliseconds
const uint16_t leadOffTimeMs = 200 , // off-time duration before first flash
const uint16_t trailOffTimeMs = 300 // off-time duration after last flash
// lead and trail time are only used when LED is on
)
bool isOn() // Returns true if LED is on, false otherwise
bool isOff() // Returns true if LED is off, false otherwise
EasyLed::State getState() // Returns the current state (On or Off)
void setState(EasyLed::State state) // Sets the current state
uint8_t pin() // Returns GPIO pin number as specified in constructor
EasyLed::ActiveLevel activeLevel() // Returns active-level as specified in constructor
EasyLed::State initialState() // Returns initialState as specified in constructorled-basics.ino 기본 사용을 보여줍니다led-advanced.ino 고급 사용을 보여줍니다led-state.ino 상태를 저장하고 복원하는 방법을 보여줍니다led-activelevel-tester.ino LED가 활성 낮은지 또는 활성 높은 지 확인하는 데 도움이됩니다.# include " EasyLed.h "
EasyLed led (LED_BUILTIN, EasyLed::ActiveLevel::Low);
void setup ()
{
...
}
void loop ()
{
readSensors ();
led. on ();
transmitSensorData ();
led. off ();
...
}