Skip to content

Commit

Permalink
Added readme, refinements on example n.5
Browse files Browse the repository at this point in the history
Signed-off-by: Fabiano Riccardi <[email protected]>
  • Loading branch information
Fabiano Riccardi committed Dec 16, 2018
1 parent 0492cea commit 0666e56
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
16 changes: 10 additions & 6 deletions examples/5_8_lights_effects/5_8_lights_effects.ino
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
#include <SoftwareSerial.h>
/**
* Some effects to test and demonstrate the potentiality of DimmableLight.
* Upload the code and select one effect through the serial port.
* Available effect list can be read in setup() function.
*
* NOTE: install https://github.com/kroimon/Arduino-SerialCommand
*/
#include <SerialCommand.h>
#include <Ticker.h>

#include "effect.h"

int pins[N_LIGHTS] = {D1,D2,D5,D6,D8,D0,D3,D4};

const int syncPin = D7;

SerialCommand serialCmd;

int effectSelected = -1;
void unrecognized(){
Serial.println("Command not recognized");
void unrecognized(const char* message){
Serial.println(String(message) + ": command not recognized");
serialCmd.clearBuffer();
}

Expand Down Expand Up @@ -108,7 +112,7 @@ void setup() {
serialCmd.addCommand("e11",[](){selectEffect(11);});
serialCmd.addCommand("e12",[](){selectEffect(12);});

serialCmd.addDefaultHandler(unrecognized);
serialCmd.setDefaultHandler(unrecognized);
}

void loop(){
Expand Down
24 changes: 24 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Dimmable Light for ESP8266
A simple library to manage up to 8 thyristors (also knows as dimmer) on ESP8266 in Arduino environment.

## Motivations
This library was born from the curiosity to learn how hardware timer works on esp8266 (precision and flexibility) and to control the old fashioned incandescence lights. I can confirm the timer is pretty poor if compared with other SoC, and a single timer (there is also Timer 0, but it is mandatory for WiFi operations) is not enough for some applications (i.e. play a tone with buzzer and simultaneously control dimmers).

## Installation
You need only Arduino IDE and ESP8266 Board Package. If you want to compile the 5th example, you also need [ArduinoSerialCommand](https://github.com/kroimon/Arduino-SerialCommand) library.

## Usage
The main APIs are accessible through DimmableLight class. First, you must instantiate one or more DimmableLight, specifying the corresponding pin. Second, you must set Zero Cross pin, calling the static method *setSyncPin(..)*. Finally you must call static method *begin()*: this activated interrupt on Zero Cross pin, hence activating thryristor whenever required. To set the delivered power level, call method *setBrightness(..)*: it accepts value from 0 to 255, fitting into 8 bit.
More details and ready-to-compile code in *examples* folder.

## Examples
There are 5 examples, enumerated from the simplest to the most complete. The 5th shows a bunch of effect applied to 8 lights. [Here](https://youtu.be/DRJcCIZw_Mw) you can find a brief video showing the 9th and 11th effect. This code make use of [this boards](https://www.ebay.it/itm/8CH-AC-LED-BULB-DIMMER-SSR-RELAY-110V-220V-SMART-HOME-ARDUINO-RASPBERRY/122631760038), but you can easily replace it with others (cheaper).
In these images you can see the full hardware setting:
!["Lamps"](https://i.ibb.co/zVBRB9k/IMG-4045.jpg "Lamps")
8 incandescence bulbs

!["Boards"](https://i.ibb.co/YN2Fktn/IMG-4041.jpg "Boards")
Wemos D1 mini (v2.3.0) and a board equipped with 8 dimmers

## Limitations
It makes use of hardware timer (Timer 1), hence it can create conflict with other functionalities like PWM, Tone and so on.

0 comments on commit 0666e56

Please sign in to comment.