Files
Licht_Wecker/LichtWecker/light.ino
2018-04-12 00:39:34 +02:00

117 lines
2.4 KiB
C++

//Show LED Colors
void show_white(){
FastLED.addLeds<WS2801, DATA_PIN, CLOCK_PIN, RBG>(leds, NUM_LEDS);
for(int i=0; i < NUM_LEDS; i = i+1 )
{
leds[i] = CRGB::White;
}
FastLED.show();
//write_log("Light: WHITE");
}
//Show LED Colors
void show_black(){
FastLED.addLeds<WS2801, DATA_PIN, CLOCK_PIN, RBG>(leds, NUM_LEDS);
for(int i=0; i < NUM_LEDS; i = i+1 )
{
leds[i] = CRGB::Black;
}
FastLED.show();
//write_log("Light: BLACK");
}
//Show LED Colors
void show_green(){
FastLED.addLeds<WS2801, DATA_PIN, CLOCK_PIN, RBG>(leds, NUM_LEDS);
for(int i=0; i < NUM_LEDS; i = i+1 )
{
leds[i] = CRGB::Green;
}
FastLED.show();
write_log("Light: GREEN");
}
void set_color(int r, int g, int b){
FastLED.addLeds<WS2801, DATA_PIN, CLOCK_PIN, RBG>(leds, NUM_LEDS);
for(int i=0; i < NUM_LEDS; i = i+1 )
{
leds[i].setRGB( r, g, b);
}
FastLED.show();
//write_log("Light: ");
//write_log(String(r));
//write_log(String(b));
//write_log(String(g));
}
bool run_wake_up(long currentMillis){
if (alarm_started == true)
{
long delta = (currentMillis - startTime)/1000;
long max_wake_time = wakeup_time *60; //Calculate Wakeuptime in Seconds
int maxvalue = int(220/(max_wake_time/3));
if (delta < (max_wake_time/3)){
int color_time = delta * maxvalue;
set_color(30 + int(color_time), int(color_time)/4, 0);
}
else if((delta < ((max_wake_time/3)*2))){
int color_time = (delta - (max_wake_time/3)) * maxvalue;
set_color(255, int(color_time)+30, int((color_time)/4));
}
else if(delta < max_wake_time){
int color_time = (delta - ((max_wake_time/3)*2)) * maxvalue;
set_color(255, 255, int((color_time))+30);
}
else{
if (delta % 2 == 0){
show_white();
}
else{
show_black();
}
return true;
}
}
else if (lamp_on == true){
}
else{
show_black();
}
return false;
}
void switch_lamp(){
if(lamp_on == false){
lamp_on = true;
show_white();
}
else{
lamp_on = false;
show_black();
}
}
void start_wake_light(long currentMillis){
if (alarm_started == false)
{
alarm_started = true;
startTime = currentMillis;
set_color(30, 0, 0);
}
}
void stop_wake_light(){
if (alarm_started == true)
{
alarm_started = false;
startTime = 0;
show_black();
}
}