added comments, copyright and license

This commit is contained in:
2014-05-01 12:05:55 +02:00
parent e26c299b67
commit 61d519e996
2 changed files with 712 additions and 6 deletions

View File

@ -1,10 +1,34 @@
/*
* IRlicht -- a 4-channel (RGBW) controller for LED-lamps, based on Arduino and
* controlled via infrared by a universal remote.
*
* Copyright 2014 Ronald Schaten <http://www.schatenseite.de>
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option)
* any later version.
*
* This program 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 General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <IRremote.h>
// pins on which the LEDs are connected
#define LED_WHITE 5
#define LED_GREEN 6
#define LED_BLUE 10
#define LED_RED 9
// use examples included in IRremote-library to find the correct values for
// your remote.
#define IR_PIN 2
#define IR_PROTOCOL 1
#define IR_FILTER 0xF70000
@ -12,7 +36,7 @@
#define IR_KEY_1 0xF720DF
#define IR_KEY_2 0xF710EF
#define IR_KEY_3 0xF730CF
#define IR_KEY_4 0xF70000 // key is broken :-(
#define IR_KEY_4 0xF70000 // key is broken on my remote :-(
#define IR_KEY_5 0xF728D7
#define IR_KEY_6 0xF7A05F
#define IR_KEY_7 0xF7906F
@ -34,6 +58,7 @@
#define IR_KEY_LIGHT15 0xF76897
#define IR_KEY_LIGHT16 0xF7E01F
// main modes of operation
#define MODE_OFF 0x00
#define MODE_CONSTANT 0x01
#define MODE_FLASH 0x02
@ -41,13 +66,14 @@
#define MODE_FADE 0x04
#define MODE_SMOOTH 0x05
int levelRed = 0x00;
// initial brightness levels
int levelRed = 0x00; // colors are off
int levelGreen = 0x00;
int levelBlue = 0x00;
int levelWhite = 0x01;
int levelTotal = 0x80;
int levelWhite = 0x10; // white is on a dark level
int levelTotal = 0x80; // overall, everything is dimmed to half
int mode = MODE_CONSTANT;
int mode = MODE_CONSTANT; // initial mode
int modestep = 0;
int modeincrement = 1;
int animationspeed = 5;
@ -56,6 +82,7 @@ long steplength = 0;
IRrecv irrecv(IR_PIN);
decode_results results;
// setRGBW sets all outputs
void setRGBW(int red, int green, int blue, int white) {
// dim all channels according to levelTotal
red = map(red, 0x00, 0xff, 0x00, levelTotal);
@ -89,8 +116,9 @@ void setup() {
void loop() {
if (irrecv.decode(&results)) {
// we received a new keypress from IR
if (results.decode_type == IR_PROTOCOL) {
if (results.value != 0xFFFFFFFF) {
if (results.value != 0xFFFFFFFF) { // only react to presses
//if (results.value & IR_MASK == IR_FILTER) {
Serial.println(results.value);
switch (results.value) {
@ -176,6 +204,7 @@ void loop() {
// do nothing, it's constant after all...
break;
case MODE_STROBE:
// flash all active channels
modestep = constrain(modestep, 0, 1);
steplength--;
if (steplength <= 0) {
@ -190,6 +219,7 @@ void loop() {
}
break;
case MODE_FLASH:
// flash between all colors
modestep = constrain(modestep, 0, 5);
steplength--;
if (steplength <= 0) {
@ -206,6 +236,7 @@ void loop() {
}
break;
case MODE_FADE:
// fade between all colors
modestep = constrain(modestep, 0x00, 6 * 0xff);
steplength--;
if (steplength <= 0) {
@ -231,6 +262,7 @@ void loop() {
}
break;
case MODE_SMOOTH:
// smooth fading of all active channels
modestep = constrain(modestep, 0x00, 0xff);
steplength--;
if (steplength <= 0) {