VLCB
Loading...
Searching...
No Matches
LED.h
Go to the documentation of this file.
1// Copyright (C) Sven Rosvall (sven@rosvall.ie)
2// This file is part of VLCB-Arduino project on https://github.com/SvenRosvall/VLCB-Arduino
3// Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
4// The full licence can be found at: http://creativecommons.org/licenses/by-nc-sa/4.0/
5
6//
7//
8//
9
10#pragma once
11
12#ifndef DEBUG_SERIAL
13#define DEBUG_SERIAL Serial
14#endif
15
16#include <Arduino.h> // for definition of byte datatype
17// #include <Streaming.h>
18
19namespace VLCB
20{
21
22const int BLINK_RATE = 500; // flash at 1Hz, 500mS on, 500mS off
23const int PULSE_ON_TIME = 10;
24
25//
27//
28class LED
29{
30public:
31 enum Mode : byte {
32 // Choose values so that lsb indicates if LED is on or off.
33 Off = 0,
34 On = 1,
38
39 IsOn = 0x01,
40 IsBlinking = 0x02,
41 IsPulsing = 0x04
42 };
43 LED();
44 explicit LED(byte pin, bool active = HIGH);
45 void setPin(byte pin, bool active = HIGH);
46 bool getState();
47 void on();
48 void off();
49 void toggle();
50 void blink(unsigned int rate = BLINK_RATE);
51 void pulse(unsigned int duration = PULSE_ON_TIME);
52
53 void run();
54
55protected:
56 byte _pin;
57 byte _mode;
58 bool _active;
59 unsigned int _interval;
60 unsigned long _timer_start;
61
62 void _update();
63};
64
65}
void toggle()
Definition LED.cpp:53
void blink(unsigned int rate=BLINK_RATE)
Definition LED.cpp:59
void off()
Definition LED.cpp:47
Mode
Definition LED.h:31
@ Off
Definition LED.h:33
@ Pulsing
Definition LED.h:37
@ On
Definition LED.h:34
@ Blinking_On
Definition LED.h:36
@ IsOn
Definition LED.h:39
@ IsBlinking
Definition LED.h:40
@ Blinking_Off
Definition LED.h:35
@ IsPulsing
Definition LED.h:41
unsigned long _timer_start
Definition LED.h:60
void pulse(unsigned int duration=PULSE_ON_TIME)
Definition LED.cpp:67
void _update()
Definition LED.cpp:112
void on()
Definition LED.cpp:41
byte _pin
Definition LED.h:56
LED()
class for individual LED with non-blocking control
Definition LED.cpp:15
void setPin(byte pin, bool active=HIGH)
Definition LED.cpp:26
bool _active
Definition LED.h:58
byte _mode
Definition LED.h:57
void run()
Definition LED.cpp:88
bool getState()
Definition LED.cpp:35
unsigned int _interval
Definition LED.h:59
Definition AbstractEventTeachingService.cpp:13
const int BLINK_RATE
Definition LED.h:22
const int PULSE_ON_TIME
Definition LED.h:23