-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
49f29a1
commit 0d3bbc4
Showing
22 changed files
with
2,032 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
{ | ||
"name": "Dimmable Light for Arduino", | ||
"version": "1.6.0", | ||
"authors": { | ||
"name": "Fabiano Riccardi", | ||
"email": "[email protected]" | ||
}, | ||
"description": "This library allows to easily control dimmers (also known as thyristors).", | ||
"keywords": [ | ||
"dimmer", | ||
"triac", | ||
"thyristor", | ||
"timer", | ||
"light", | ||
"arduino-library", | ||
"phase-fired control" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/fabianoriccardi/dimmable-light" | ||
}, | ||
"licence": "LGPL-2.1-or-later", | ||
"frameworks": [ | ||
"arduino" | ||
], | ||
"platforms": [ | ||
"espressif8266", | ||
"espressif32", | ||
"atmelavr", | ||
"atmelsam", | ||
"raspberrypi" | ||
], | ||
"dependencies": [ | ||
{ | ||
"owner": "mike-matera", | ||
"name": "ArduinoSTL", | ||
"version": "^1.3.3", | ||
"platforms": [ | ||
"atmelavr" | ||
] | ||
} | ||
], | ||
"examples": [ | ||
{ | ||
"name": "1_dimmable_light", | ||
"base": "examples/1_dimmable_light", | ||
"files": [ | ||
"1_dimmable_light.ino" | ||
] | ||
}, | ||
{ | ||
"name": "2_dimmable_lights", | ||
"base": "examples/2_dimmable_lights", | ||
"files": [ | ||
"2_dimmable_lights.ino" | ||
] | ||
}, | ||
{ | ||
"name": "3_dimmable_light_5_light", | ||
"base": "examples/3_dimmable_light_5_light", | ||
"files": [ | ||
"3_dimmable_light_5_light.ino" | ||
] | ||
}, | ||
{ | ||
"name": "4_lights_manager", | ||
"base": "examples/4_lights_manager", | ||
"files": [ | ||
"4_lights_manager.ino" | ||
] | ||
}, | ||
{ | ||
"name": "5_dimmable_manager_n_lights", | ||
"base": "examples/5_dimmable_manager_n_lights", | ||
"files": [ | ||
"5_dimmable_manager_n_lights.ino" | ||
] | ||
}, | ||
{ | ||
"name": "6_8_lights_effects", | ||
"base": "examples/6_8_lights_effects", | ||
"files": [ | ||
"6_8_lights_effects.ino" | ||
] | ||
}, | ||
{ | ||
"name": "7_linearized_dimmable_light", | ||
"base": "examples/7_linearized_dimmable_light", | ||
"files": [ | ||
"7_linearized_dimmable_light.ino" | ||
] | ||
}, | ||
{ | ||
"name": "8_set_frequency_automatically", | ||
"base": "examples/8_set_frequency_automatically", | ||
"files": [ | ||
"8_set_frequency_automatically.ino" | ||
] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
name=Dimmable Light for Arduino | ||
version=1.6.0 | ||
author=Fabiano Riccardi <[email protected]> | ||
maintainer=Fabiano Riccardi <[email protected]> | ||
sentence=This library allows to easily control dimmers (also known as thyristors). | ||
paragraph=This library was born to control dimmable light bulbs, but actually dimmers are fully compatible with other AC loads like electrical heaters and motors (be aware of what you are doing!). Actually it works on ESP8266, ESP32, AVR and SAMD. | ||
category=Device Control | ||
url=https://github.com/fabianoriccardi/dimmable-light | ||
architectures=esp8266,esp32,avr,samd,rp2040 | ||
depends=ArduinoSTL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/****************************************************************************** | ||
* This file is part of Dimmable Light for Arduino, a library to control * | ||
* dimmers. * | ||
* * | ||
* Copyright (C) 2018-2023 Fabiano Riccardi * | ||
* * | ||
* Dimmable Light for Arduino is free software; you can redistribute * | ||
* it and/or modify it under the terms of the GNU Lesser General Public * | ||
* License as published by the Free Software Foundation; either * | ||
* version 2.1 of the License, or (at your option) any later version. * | ||
* * | ||
* This library is distributed in the hope that it will be useful, * | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of * | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * | ||
* Lesser General Public License for more details. * | ||
* * | ||
* You should have received a copy of the GNU Lesser General Public License * | ||
* along with this library; if not, see <http://www.gnu.org/licenses/>. * | ||
******************************************************************************/ | ||
#ifndef CIRCULAR_QUEUE_H | ||
#define CIRCULAR_QUEUE_H | ||
|
||
/* | ||
* A minimal static circular queue. | ||
* It supports only insertion, and older values are automatically overwritten. | ||
*/ | ||
template<typename T, int N> class CircularQueue { | ||
public: | ||
/** | ||
* Construct a new Circular Queue object filling it with zeros or | ||
* using the default constructor of type T. | ||
*/ | ||
CircularQueue() : arr{ 0 } {}; | ||
|
||
/** | ||
* Insert an element. If full, it returns the overwritten element. | ||
*/ | ||
T insert(T value) { | ||
T ret = arr[index]; | ||
arr[index] = value; | ||
if (value > max) { max = value; } | ||
total += value; | ||
total -= ret; | ||
index++; | ||
if (index == N) { index = 0; } | ||
if (n < N) { n++; } | ||
|
||
return ret; | ||
}; | ||
|
||
/** | ||
* Empty the queue. | ||
*/ | ||
void reset() { | ||
for (int i = 0; i < N; i++) { arr[i] = 0; } | ||
n = 0; | ||
index = 0; | ||
total = 0; | ||
} | ||
|
||
/** | ||
* Return the number of stored elements. | ||
*/ | ||
int getCount() const { return n; }; | ||
T getTotal() const { return total; } | ||
T getMax() const { return max; } | ||
T getLast() const { return index == 0 ? arr[N - 1] : arr[index - 1]; } | ||
|
||
private: | ||
T arr[N]; | ||
|
||
T total = 0; | ||
T max = 0; | ||
|
||
// The position for the next element to be inserted | ||
int index = 0; | ||
|
||
// Number of elements currently stored | ||
int n = 0; | ||
}; | ||
|
||
#endif // END CIRCULAR_QUEUE_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/****************************************************************************** | ||
* This file is part of Dimmable Light for Arduino, a library to control * | ||
* dimmers. * | ||
* * | ||
* Copyright (C) 2018-2023 Fabiano Riccardi * | ||
* * | ||
* Dimmable Light for Arduino is free software; you can redistribute * | ||
* it and/or modify it under the terms of the GNU Lesser General Public * | ||
* License as published by the Free Software Foundation; either * | ||
* version 2.1 of the License, or (at your option) any later version. * | ||
* * | ||
* This library is distributed in the hope that it will be useful, * | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of * | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * | ||
* Lesser General Public License for more details. * | ||
* * | ||
* You should have received a copy of the GNU Lesser General Public License * | ||
* along with this library; if not, see <http://www.gnu.org/licenses/>. * | ||
******************************************************************************/ | ||
#ifdef ESP32 | ||
|
||
#include "hw_timer_esp32.h" | ||
|
||
const static int TIMER_ID = 0; | ||
|
||
static hw_timer_t* timer = nullptr; | ||
|
||
void timerInit(void (*callback)()) { | ||
#if ESP_IDF_VERSION_MAJOR >= 5 | ||
timer = timerBegin(1000000); | ||
timerWrite(timer, 0); | ||
timerAttachInterrupt(timer, callback); | ||
#else | ||
// Use 1st timer of 4 (counted from zero). | ||
// Set 80 divider for prescaler (see ESP32 Technical Reference Manual for more | ||
// info), count up. The counter starts to increase its value. | ||
timer = timerBegin(TIMER_ID, 80, true); | ||
timerStop(timer); | ||
timerWrite(timer, 0); | ||
|
||
timerAttachInterrupt(timer, callback, false); | ||
#endif | ||
} | ||
|
||
void ARDUINO_ISR_ATTR startTimerAndTrigger(uint32_t delay) { | ||
#if ESP_IDF_VERSION_MAJOR >= 5 | ||
timerRestart(timer); | ||
timerAlarm(timer, delay, false, 0); | ||
#else | ||
timerWrite(timer, 0); | ||
timerAlarmWrite(timer, delay, false); | ||
timerAlarmEnable(timer); | ||
timerStart(timer); | ||
#endif | ||
} | ||
|
||
void ARDUINO_ISR_ATTR setAlarm(uint32_t delay) { | ||
#if ESP_IDF_VERSION_MAJOR >= 5 | ||
timerAlarm(timer, delay, false, 0); | ||
#else | ||
timerAlarmWrite(timer, delay, false); | ||
|
||
// On core v2.0.0-2.0.1, the timer alarm is automatically disabled after triggering, | ||
// so re-enable the alarm | ||
timerAlarmEnable(timer); | ||
#endif | ||
} | ||
|
||
void ARDUINO_ISR_ATTR stopTimer() { | ||
#if ESP_IDF_VERSION_MAJOR < 5 | ||
timerStop(timer); | ||
#endif | ||
} | ||
|
||
#endif // END ESP32 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/****************************************************************************** | ||
* This file is part of Dimmable Light for Arduino, a library to control * | ||
* dimmers. * | ||
* * | ||
* Copyright (C) 2018-2023 Fabiano Riccardi * | ||
* * | ||
* Dimmable Light for Arduino is free software; you can redistribute * | ||
* it and/or modify it under the terms of the GNU Lesser General Public * | ||
* License as published by the Free Software Foundation; either * | ||
* version 2.1 of the License, or (at your option) any later version. * | ||
* * | ||
* This library is distributed in the hope that it will be useful, * | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of * | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * | ||
* Lesser General Public License for more details. * | ||
* * | ||
* You should have received a copy of the GNU Lesser General Public License * | ||
* along with this library; if not, see <http://www.gnu.org/licenses/>. * | ||
******************************************************************************/ | ||
#ifndef HW_TIMER_ESP32_H | ||
#define HW_TIMER_ESP32_H | ||
|
||
#include <Arduino.h> | ||
|
||
// This workaround is necessary to support compilation on ESP32-Arduino v1.0.x | ||
#ifndef ARDUINO_ISR_ATTR | ||
#define ARDUINO_ISR_ATTR | ||
#endif | ||
|
||
void timerInit(void (*callback)()); | ||
|
||
void startTimerAndTrigger(uint32_t delay); | ||
|
||
void setAlarm(uint32_t delay); | ||
|
||
void stopTimer(); | ||
|
||
#endif // END HW_TIMER_ESP32_H |
Oops, something went wrong.