66 lines
1.5 KiB
C++
66 lines
1.5 KiB
C++
/*
|
|
* Led.h
|
|
*
|
|
* Created: 03.11.2013 17:11:58
|
|
* Author: BlubbFish
|
|
*/
|
|
|
|
#ifndef LED_H_
|
|
#define LED_H_
|
|
|
|
#include "pin.hpp"
|
|
|
|
template <typename Port, int pin_red, int pin_green, int pin_blue>
|
|
class Led {
|
|
public:
|
|
Led() {
|
|
init();
|
|
}
|
|
void color(uint8_t mask) {
|
|
(mask & (1<<0)) ? blue::make_high() : blue::make_low();
|
|
(mask & (1<<1)) ? green::make_high() : green::make_low();
|
|
(mask & (1<<2)) ? red::make_high() : red::make_low();
|
|
}
|
|
void rainbow(uint8_t time) {
|
|
fade(RED, YELLOW, time);
|
|
fade(YELLOW, GREEN, time);
|
|
fade(GREEN, CYAN, time);
|
|
fade(CYAN, BLUE, time);
|
|
fade(BLUE, MAGENTA, time);
|
|
fade(MAGENTA, RED, time);
|
|
}
|
|
void fade(uint8_t from, uint8_t to, uint8_t dur) {
|
|
for (uint8_t i=0;i<0xFF;i++) {
|
|
for(uint8_t k=0;k<dur;k++) {
|
|
for (uint8_t j=i;j<0xFF;j++) {
|
|
color(from);
|
|
}
|
|
for (int j=0;j<i;j++) {
|
|
color(to);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
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;
|
|
private:
|
|
void init() {
|
|
red::make_output();
|
|
green::make_output();
|
|
blue::make_output();
|
|
}
|
|
void uninit();
|
|
const typedef avrlib::pin<Port, pin_red> red;
|
|
const typedef avrlib::pin<Port, pin_green> green;
|
|
const typedef avrlib::pin<Port, pin_blue> blue;
|
|
};
|
|
|
|
|
|
|
|
#endif /* LED_H_ */ |