Skip to content

Latest commit

 

History

History
111 lines (69 loc) · 2.24 KB

README.md

File metadata and controls

111 lines (69 loc) · 2.24 KB

MoodLamp

This is a simple Arduino-like Library that controls any RGB Led through 3 PWM Pins.

This library works with ESP8266 NodeMCU too.

With an RGB Led you could create best light projects. But not only this, you could use and RGB Led to test a lot of sensor and other things with microcontrollers.

The idea of this library is to let your code clean, and provide a variet of functions to control your projects.

In this repository you will find a series of examples how to use MoodLamp.

Steps:

  1. Download the Library or clone it.
  2. Open Arduino IDE and go to menu : Sketch > Include Library > Add .zip library. Then choose the downloaded file
  3. See the Library examples that come with the library: File > Examples > MoodLamp

Basics

To use this library in a new project do this:

  • Include the library
#include <MoodLamp.h>
  • Define what PWM pins will control the led
const byte PIN_RED   = 3;
const byte PIN_GREEN = 5;
const byte PIN_BLUE  = 6;
  • Create the object passing the pins
MoodLamp moodlamp(PIN_RED,PIN_GREEN,PIN_BLUE);
  • on setup() function uses the begin() function to initialize the object
void setup() {
  // put your setup code here, to run once:
  
  moodlamp.begin();    // set the pinModes
  
}
  • You could set the main function of the object on setup() too. This examples sets the wheel() function to change the color over time
void setup() {
  // put your setup code here, to run once:
  
  moodlamp.begin();    // set the pinModes
  moodlamp.wheel(1);   // wheel function. 
}
  • in the loop() function, uses update()
void loop() {

  // update the lamp color.
  moodlamp.update();    

}

This is a basic example of how to use the library.

You could change the color using

moodlamp.color(COLOR_CYAN);

The color will vary from 0 to 359. 360; Red to Blue. 360 is White. this follows the Color Wheel.

Change the brightness

moodlamp.brightness(50);

brightness vary from 0 - 100 in percentage.

Or use the fade function

moodlamp.fade(1)

And it's possible to change the speed of the function

moodlamp.fade_speed(30);

To see more information about all the library functions please see the Wiki.

Thanks