/* * Led.h * * Created: 03.11.2013 17:11:58 * Author: BlubbFish */ #ifndef STRIPE_H_ #define STRIPE_H_ #include "hardware/pin.hpp" #include template class Stripe { public: Stripe() { this->init(); } void color(uint8_t r, uint8_t g, uint8_t b) { OCR0B=r; //ROT OCR2B=g; //GRÜN OCR2A=b; //BLAU } void setcolor(uint8_t mask) { (mask & (1<<0)) ? OCR2A=0xFF : OCR2A=0x00; (mask & (1<<1)) ? OCR2B=0xFF : OCR2B=0x00; (mask & (1<<2)) ? OCR0B=0xFF : OCR0B=0x00; } static const uint8_t BLACK = 0; static const uint8_t BLUE = 1; static const uint8_t GREEN = 2; static const uint8_t CYAN = 3; static const uint8_t RED = 4; static const uint8_t MAGENTA = 5; static const uint8_t YELLOW = 6; static const uint8_t WHITE = 7; void off() { this->timerOff(); stripered::make_low(); stripegreen::make_low(); stripeblue::make_low(); } void on() { this->timerOn(); } void lower() { if(OCR0B >= 5) { OCR0B = OCR0B - 5; } else { OCR0B = 0; } if(OCR2B >= 5) { OCR2B = OCR2B - 5; } else { OCR2B = 0; } if(OCR2A >= 5) { OCR2A = OCR2A - 5; } else { OCR2A = 0; } } void higher() { if(OCR0B <= 250) { OCR0B = OCR0B + 5; } else { OCR0B = 0; } if(OCR2B <= 250) { OCR2B = OCR2B + 5; } else { OCR2B = 0; } if(OCR2A <= 250) { OCR2A = OCR2A + 5; } else { OCR2A = 0; } } void fadeto(uint8_t red, uint8_t green, uint8_t blue, uint8_t time) { this->setfadecolor(0, red, green, blue, time); this->fade_zylk = 1; } void setfadecolor(uint8_t index, uint8_t red, uint8_t green, uint8_t blue, uint8_t time) { this->fademap[0][index] = red; this->fademap[1][index] = green; this->fademap[2][index] = blue; this->fademap[3][index] = time; } void interrupt() { if(this->fade_zylk > 0) { if(this->fadesteps[0] == 0 && this->fadesteps[1] == 0 && this->fadesteps[2] == 0) { this->fadesteps[0] = (this->fademap[0][this->fade_zylk-1]-OCR0B)/this->fademap[3][this->fade_zylk-1]; //Calc Red; this->fadesteps[1] = (this->fademap[1][this->fade_zylk-1]-OCR2B)/this->fademap[3][this->fade_zylk-1]; //Calc Green; this->fadesteps[2] = (this->fademap[2][this->fade_zylk-1]-OCR2A)/this->fademap[3][this->fade_zylk-1]; //Calc Blue; } else { if((this->fadesteps[0] > 0 && (OCR0B + this->fadesteps[0]) <= this->fademap[0][this->fade_zylk-1]) || (this->fadesteps[0] < 0 && (OCR0B + this->fadesteps[0]) >= this->fademap[0][this->fade_zylk-1])) { OCR0B = OCR0B + this->fadesteps[0]; } else { OCR0B = this->fademap[0][this->fade_zylk-1]; this->fadesteps[0] = 0; } if((this->fadesteps[1] > 0 && (OCR2B + this->fadesteps[1]) <= this->fademap[1][this->fade_zylk-1]) || (this->fadesteps[1] < 0 && (OCR2B + this->fadesteps[1]) >= this->fademap[1][this->fade_zylk-1])) { OCR2B = OCR2B + this->fadesteps[1]; } else { OCR2B = this->fademap[1][this->fade_zylk-1]; this->fadesteps[1] = 0; } if((this->fadesteps[2] > 0 && (OCR2A + this->fadesteps[2]) <= this->fademap[2][this->fade_zylk-1]) || (this->fadesteps[2] < 0 && (OCR2A + this->fadesteps[2]) >= this->fademap[2][this->fade_zylk-1])) { OCR2A = OCR2A + this->fadesteps[2]; } else { OCR2A = this->fademap[2][this->fade_zylk-1]; this->fadesteps[2] = 0; } } } } private: uint8_t fade_zylk; uint8_t fademap[4][5]; float fadesteps[3]; void init() { stripered::make_output(); stripegreen::make_output(); stripeblue::make_output(); this->fade_zylk = 0; this->initTimer(); this->color(0, 0, 0); } void timerOff() { // OC0B output: Disconnected // OC2A output: Disconnected // OC2B output: Disconnected TCCR0A &= ~(1<timerOn(); } const typedef avrlib::pin stripered; const typedef avrlib::pin stripegreen; const typedef avrlib::pin stripeblue; }; #endif /* STRIPE_H_ */